mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
113146419-script_changes
This commit is contained in:
parent
4fbb071e3e
commit
334e2b1362
1 changed files with 23 additions and 17 deletions
|
@ -8,33 +8,39 @@ namespace :epp do
|
|||
desc 'Trim logs'
|
||||
task trim_documents: :environment do
|
||||
puts '-----> Running query'
|
||||
puts '-----> Selecting count of all rows'
|
||||
|
||||
rows = ApiLog::EppLog.where("request ~* ?", '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>')
|
||||
count = rows.count
|
||||
|
||||
puts "-----> Total rows #{count}"
|
||||
|
||||
start = Time.zone.now.to_f
|
||||
|
||||
i = 0
|
||||
ids = []
|
||||
count = 0
|
||||
|
||||
ApiLog::EppLog.where("request ~* ?", '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>').find_each(batch_size: 10000)do |x|
|
||||
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
|
||||
trimmed = x.request.gsub(/<eis:legalDocument([^>]+)>([^<])+<\/eis:legalDocument>/, "<eis:legalDocument>[FILTERED]</eis:legalDocument>")
|
||||
|
||||
ids.push x.id
|
||||
i += 1
|
||||
x.request = trimmed
|
||||
|
||||
if i = 500
|
||||
i = 0
|
||||
puts "500 rows updated #{ids.join(', ')}"
|
||||
end
|
||||
x.save and ids.push x.id and i += 1 and ids.push x.id
|
||||
|
||||
i += 1
|
||||
count += 1
|
||||
|
||||
if i == 100
|
||||
puts "-----> Total rows updated #{count}"
|
||||
puts "Last #{i} rows ids #{ids.join(', ')}"
|
||||
i = 0
|
||||
ids = []
|
||||
end
|
||||
|
||||
end
|
||||
puts "-----> Query done"
|
||||
|
||||
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