* Add: #581 NGワード検出履歴を定期的に削除する処理 * マイグレーションコードを修正
This commit is contained in:
parent
aec832e257
commit
b2acc7dbb8
6 changed files with 26 additions and 1 deletions
|
@ -12,6 +12,7 @@ class Vacuum::NgHistoriesVacuum
|
|||
private
|
||||
|
||||
def vacuum_histories!
|
||||
NgwordHistory.where('created_at < ?', HISTORY_LIFE_DURATION.ago).in_batches.destroy_all
|
||||
NgRuleHistory.where('created_at < ?', HISTORY_LIFE_DURATION.ago).in_batches.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class IndexToSortForNgWordCreatedDate < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :ngword_histories, :created_at, algorithm: :concurrently
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_27_033337) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_27_222450) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -936,6 +936,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_27_033337) do
|
|||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "count", default: 0, null: false
|
||||
t.index ["created_at"], name: "index_ngword_histories_on_created_at"
|
||||
t.index ["uri", "keyword", "created_at"], name: "index_ngword_histories_on_uri_and_keyword_and_created_at"
|
||||
t.index ["uri", "reason", "created_at"], name: "index_ngword_histories_on_uri_and_reason_and_created_at"
|
||||
end
|
||||
|
|
|
@ -90,6 +90,7 @@ namespace :dangerous do
|
|||
20240217230006
|
||||
20240218233621
|
||||
20240227033337
|
||||
20240227222450
|
||||
)
|
||||
# Removed: account_groups
|
||||
target_tables = %w(
|
||||
|
|
9
spec/fabricators/ngword_history_fabricator.rb
Normal file
9
spec/fabricators/ngword_history_fabricator.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:ngword_history) do
|
||||
uri 'https://test.com/'
|
||||
target_type 0
|
||||
reason 0
|
||||
text 'this is an invalid text'
|
||||
keyword 'invalid'
|
||||
end
|
|
@ -6,6 +6,8 @@ RSpec.describe Vacuum::NgHistoriesVacuum do
|
|||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let!(:word_history_old) { Fabricate(:ngword_history, created_at: 30.days.ago) }
|
||||
let!(:word_history_recent) { Fabricate(:ngword_history, created_at: 2.days.ago) }
|
||||
let!(:rule_history_old) { Fabricate(:ng_rule_history, created_at: 30.days.ago) }
|
||||
let!(:rule_history_recent) { Fabricate(:ng_rule_history, created_at: 2.days.ago) }
|
||||
|
||||
|
@ -14,10 +16,12 @@ RSpec.describe Vacuum::NgHistoriesVacuum do
|
|||
end
|
||||
|
||||
it 'deletes old history' do
|
||||
expect { word_history_old.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
expect { rule_history_old.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'does not delete recent history' do
|
||||
expect { word_history_recent.reload }.to_not raise_error
|
||||
expect { rule_history_recent.reload }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue