Skip to content

Commit

Permalink
perf: patch reading time (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmrf authored Oct 25, 2024
1 parent b34b0fd commit 8404dcd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
en:
site_settings:
discourse_plugin_last_day_used_key_enabled: "Change last used strategy to use last day instead of last time"
discourse_plugin_db_patches: "Activates db write patches for perf optimizations"
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins:
discourse_plugin_last_day_used_key_enabled:
discourse_plugin_db_patches:
default: false
client: true
29 changes: 21 additions & 8 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

# name: discourse-plugin-last-day-used-key
# name: discourse-plugin-db-patches
# about: changes last used strategy to use current day instead of current time
# version: 0.0.1
# authors: Marfeel
# url: https://github.com/Marfeel/discourse-plugin-last-day-used-key
# url: https://github.com/Marfeel/discourse-plugin-db-patches
# required_version: 2.7.0

enabled_site_setting :discourse_plugin_markdown_html_whitelist_enabled
enabled_site_setting :discourse_plugin_db_patches

module ::LastDayUsedKey
PLUGIN_NAME = "discourse-plugin-last-day-used-key"
module ::DBPatches
PLUGIN_NAME = "discourse-plugin-db-patches"

module UserApiKeyExtensions
def update_last_used(client_id)
Expand Down Expand Up @@ -63,10 +63,23 @@ def record_new_timing(args)
end
end
end

module UserStatExtension
def self.prepended(base)
base.singleton_class.prepend(ClassMethods)
end

module ClassMethods
def self.update_time_read!(id)

end
end
end
end

after_initialize do
::UserApiKey.prepend(::LastDayUsedKey::UserApiKeyExtensions)
::ApiKey.prepend(::LastDayUsedKey::ApiKeyExtensions)
::PostTiming.prepend(::LastDayUsedKey::PostTimingExtensions)
::UserApiKey.prepend(::DBPatches::UserApiKeyExtensions)
::ApiKey.prepend(::DBPatches::ApiKeyExtensions)
::PostTiming.prepend(::DBPatches::PostTimingExtensions)
::UserStat.prepend(::DBPatches::UserStatExtension)
end
2 changes: 1 addition & 1 deletion spec/plugin_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# spec/plugin_spec.rb
# frozen_string_literal: true

RSpec.describe LastDayUsedKey do
RSpec.describe DBPatches do
let(:user) { Fabricate(:user) }
let(:user_api_key) { Fabricate(:user_api_key, user: user) }
let(:api_key) { Fabricate(:api_key, user: user) }
Expand Down

0 comments on commit 8404dcd

Please sign in to comment.