mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FIX: bust preview
FIX: safeguard for huge delta backfill
This commit is contained in:
parent
792c73a671
commit
e6f0b94b3a
@ -123,8 +123,9 @@ class BadgeGranter
|
||||
end
|
||||
|
||||
def self.preview(sql, opts = {})
|
||||
params = {user_ids: [], post_ids: [], backfill: true}
|
||||
count_sql = "SELECT COUNT(*) count FROM (#{sql}) q"
|
||||
grant_count = SqlBuilder.map_exec(OpenStruct, count_sql).first.count
|
||||
grant_count = SqlBuilder.map_exec(OpenStruct, count_sql, params).first.count
|
||||
|
||||
grants_sql =
|
||||
if opts[:target_posts]
|
||||
@ -141,13 +142,14 @@ class BadgeGranter
|
||||
LIMIT 10"
|
||||
end
|
||||
|
||||
sample = SqlBuilder.map_exec(OpenStruct, grants_sql).map(&:to_h)
|
||||
sample = SqlBuilder.map_exec(OpenStruct, grants_sql, params).map(&:to_h)
|
||||
|
||||
{grant_count: grant_count, sample: sample}
|
||||
rescue => e
|
||||
{error: e.to_s}
|
||||
end
|
||||
|
||||
MAX_ITEMS_FOR_DELTA = 200
|
||||
def self.backfill(badge, opts=nil)
|
||||
return unless badge.query.present? && badge.enabled
|
||||
|
||||
@ -157,6 +159,13 @@ class BadgeGranter
|
||||
post_ids = nil unless post_ids.present?
|
||||
user_ids = nil unless user_ids.present?
|
||||
|
||||
# safeguard fall back to full backfill if more than 200
|
||||
if (post_ids && post_ids.length > MAX_ITEMS_FOR_DELTA) ||
|
||||
(user_ids && user_ids.length > MAX_ITEMS_FOR_DELTA)
|
||||
post_ids = nil
|
||||
user_ids = nil
|
||||
end
|
||||
|
||||
full_backfill = !user_ids && !post_ids
|
||||
|
||||
post_clause = badge.target_posts ? "AND (q.post_id = ub.post_id OR NOT :multiple_grant)" : ""
|
||||
|
Loading…
Reference in New Issue
Block a user