mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
Clean up job for search logs
This commit is contained in:
parent
d7f783ffed
commit
6b6ad9391b
9
app/jobs/scheduled/clean_up_search_logs.rb
Normal file
9
app/jobs/scheduled/clean_up_search_logs.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Jobs
|
||||
class CleanUpSearchLogs < Jobs::Scheduled
|
||||
every 1.week
|
||||
|
||||
def execute(args)
|
||||
SearchLog.clean_up
|
||||
end
|
||||
end
|
||||
end
|
|
@ -44,4 +44,11 @@ class SearchLog < ActiveRecord::Base
|
|||
[:updated, rows[0]['id'].to_i]
|
||||
end
|
||||
end
|
||||
|
||||
def self.clean_up
|
||||
search_id = SearchLog.order(:id).offset(SiteSetting.search_query_log_max_size).limit(1).pluck(:id)
|
||||
if search_id.present?
|
||||
SearchLog.where('id < ?', search_id[0]).delete_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -948,6 +948,7 @@ en:
|
|||
search_prefer_recent_posts: "If searching your large forum is slow, this option tries an index of more recent posts first"
|
||||
search_recent_posts_size: "How many recent posts to keep in the index"
|
||||
log_search_queries: "Log search queries performed by users"
|
||||
search_query_log_max_size: "Maximum amount of search queries to keep"
|
||||
allow_uncategorized_topics: "Allow topics to be created without a category. WARNING: If there are any uncategorized topics, you must recategorize them before turning this off."
|
||||
allow_duplicate_topic_titles: "Allow topics with identical, duplicate titles."
|
||||
unique_posts_mins: "How many minutes before a user can make a post with the same content again"
|
||||
|
|
|
@ -1155,6 +1155,7 @@ search:
|
|||
search_prefer_recent_posts: false
|
||||
search_recent_posts_size: 100000
|
||||
log_search_queries: true
|
||||
search_query_log_max_size: 1000000
|
||||
|
||||
uncategorized:
|
||||
version_checks:
|
||||
|
|
|
@ -137,6 +137,26 @@ RSpec.describe SearchLog, type: :model do
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "clean_up" do
|
||||
|
||||
it "will remove old logs" do
|
||||
SearchLog.log(term: 'jawa', search_type: :header, ip_address: '127.0.0.1')
|
||||
SearchLog.log(term: 'jedi', search_type: :header, ip_address: '127.0.0.1')
|
||||
SearchLog.log(term: 'rey', search_type: :header, ip_address: '127.0.0.1')
|
||||
SearchLog.log(term: 'finn', search_type: :header, ip_address: '127.0.0.1')
|
||||
|
||||
SiteSetting.search_query_log_max_size = 5
|
||||
SearchLog.clean_up
|
||||
expect(SearchLog.count).to eq(4)
|
||||
|
||||
SiteSetting.search_query_log_max_size = 2
|
||||
SearchLog.clean_up
|
||||
expect(SearchLog.count).to eq(2)
|
||||
expect(SearchLog.where(term: 'rey').first).to be_present
|
||||
expect(SearchLog.where(term: 'finn').first).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user