mirror of
https://github.com/internetee/registry.git
synced 2025-05-28 09:51:03 +02:00
Merge branch '113146419-reduce_db_size' into staging
This commit is contained in:
commit
f9bf2f671f
1 changed files with 29 additions and 5 deletions
|
@ -8,12 +8,36 @@ namespace :epp do
|
|||
desc 'Trim logs'
|
||||
task trim_documents: :environment do
|
||||
puts '-----> Running query'
|
||||
sql = <<-SQL
|
||||
UPDATE epp_logs SET request = regexp_replace(request, '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>', '<eis:legalDocument>[FILTERED]<\eis:legalDocument>');
|
||||
SQL
|
||||
ApiLog::EppLog.connection.execute(sql)
|
||||
|
||||
puts "-----> Query done"
|
||||
start = Time.zone.now.to_f
|
||||
|
||||
i = 0
|
||||
ids = []
|
||||
count = 0
|
||||
|
||||
ApiLog::EppLog
|
||||
.where("request ~* ?", '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>')
|
||||
.where("request NOT LIKE ?", "%<eis:legalDocument>[FILTERED]</eis:legalDocument>%")
|
||||
.where("request NOT LIKE ?", '%<eis:legalDocument type="pdf"></eis:legalDocument>%').find_each(batch_size: 1000)do |x|
|
||||
|
||||
trimmed = x.request.gsub(/<eis:legalDocument([^>]+)>([^<])+<\/eis:legalDocument>/, "<eis:legalDocument>[FILTERED]</eis:legalDocument>")
|
||||
|
||||
x.request = trimmed
|
||||
|
||||
x.save and count += 1 and i += 1 and ids.push x.id
|
||||
|
||||
if i == 500
|
||||
puts "-----> Total rows updated #{count}"
|
||||
puts "Last #{i} rows ids #{ids.join(', ')}"
|
||||
i = 0
|
||||
ids = []
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
puts "-----> Total rows updated #{count}"
|
||||
puts "Last #{count} rows ids #{ids.join(', ')}"
|
||||
puts "-----> Query done total #{(Time.zone.now.to_f - start).round(2)} seconds"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue