mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 11:55:09 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
33 lines
687 B
Ruby
33 lines
687 B
Ruby
# frozen_string_literal: true
|
|
|
|
task 'redis:clean_up' => ['environment'] do
|
|
return unless Rails.configuration.multisite
|
|
|
|
dbs = RailsMultisite::ConnectionManagement.all_dbs
|
|
dbs << Discourse::SIDEKIQ_NAMESPACE
|
|
|
|
regexp = /((\$(?<message_bus>\w+)$)|(^?(?<namespace>\w+):))/
|
|
|
|
cursor = 0
|
|
redis = $redis.without_namespace
|
|
|
|
loop do
|
|
cursor, keys = redis.scan(cursor)
|
|
cursor = cursor.to_i
|
|
|
|
redis.multi do
|
|
keys.each do |key|
|
|
if match = key.match(regexp)
|
|
db_name = match[:message_bus] || match[:namespace]
|
|
|
|
if !dbs.include?(db_name)
|
|
redis.del(key)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
break if cursor == 0
|
|
end
|
|
end
|