mirror of
https://github.com/internetee/registry.git
synced 2025-08-13 13:09:32 +02:00
113146419-new_task
This commit is contained in:
parent
cf7b9bcacf
commit
4fbb071e3e
1 changed files with 26 additions and 5 deletions
|
@ -8,11 +8,32 @@ namespace :epp do
|
||||||
desc 'Trim logs'
|
desc 'Trim logs'
|
||||||
task trim_documents: :environment do
|
task trim_documents: :environment do
|
||||||
puts '-----> Running query'
|
puts '-----> Running query'
|
||||||
sql = <<-SQL
|
puts '-----> Selecting count of all rows'
|
||||||
UPDATE epp_logs SET request = regexp_replace(request, '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>', '<eis:legalDocument>[FILTERED]<\eis:legalDocument>');
|
|
||||||
SQL
|
|
||||||
ApiLog::EppLog.connection.execute(sql)
|
|
||||||
|
|
||||||
|
rows = ApiLog::EppLog.where("request ~* ?", '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>')
|
||||||
|
count = rows.count
|
||||||
|
|
||||||
|
puts "-----> Total rows #{count}"
|
||||||
|
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
ids = []
|
||||||
|
|
||||||
|
ApiLog::EppLog.where("request ~* ?", '<eis:legalDocument(.|\n)*?<\/eis:legalDocument>').find_each(batch_size: 10000)do |x|
|
||||||
|
|
||||||
|
trimmed = x.request.gsub(/<eis:legalDocument([^>]+)>([^<])+<\/eis:legalDocument>/, "<eis:legalDocument>[FILTERED]</eis:legalDocument>")
|
||||||
|
x.request = trimmed
|
||||||
|
x.save
|
||||||
|
|
||||||
|
ids.push x.id
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
if i = 500
|
||||||
|
i = 0
|
||||||
|
puts "500 rows updated #{ids.join(', ')}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
puts "-----> Query done"
|
puts "-----> Query done"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue