diff --git a/app/models/badge.rb b/app/models/badge.rb index 0f9542ec7..199e4428b 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -28,7 +28,9 @@ class Badge < ActiveRecord::Base FamousLink = 30 Admired = 31 GivesBack = 32 - Generous = 33 + OutOfLove = 33 + MyCupRunnethOver = 34 + CrazyInLove = 35 # other consts AutobiographerMinBioLength = 10 @@ -220,14 +222,6 @@ SQL HAVING us.likes_given::float / count(*) > 5.0 SQL - Generous = <<-SQL - SELECT uh.target_user_id AS user_id, MIN(uh.created_at) AS granted_at - FROM user_histories AS uh - WHERE uh.action = #{UserHistory.actions[:rate_limited_like]} - AND (:backfill OR uh.target_user_id IN (:user_ids)) - GROUP BY uh.target_user_id -SQL - def self.invite_badge(count,trust_level) " SELECT u.id user_id, current_timestamp granted_at @@ -292,6 +286,17 @@ SQL SQL end + def self.like_rate_limit(count) + <<-SQL + SELECT uh.target_user_id AS user_id, MAX(uh.created_at) AS granted_at + FROM user_histories AS uh + WHERE uh.action = #{UserHistory.actions[:rate_limited_like]} + AND (:backfill OR uh.target_user_id IN (:user_ids)) + GROUP BY uh.target_user_id + HAVING COUNT(*) >= #{count} + SQL + end + end belongs_to :badge_type @@ -313,7 +318,6 @@ SQL [:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable] end - def self.trust_level_badge_ids (1..4).to_a end diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index bfb86cf86..7783e0848 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -316,18 +316,27 @@ Badge.seed do |b| b.system = true end -Badge.seed do |b| - b.id = Badge::Generous - b.default_name = "Generous" - b.default_icon = "fa-heart" - b.badge_type_id = BadgeType::Silver - b.query = Badge::Queries::Generous - b.default_badge_grouping_id = BadgeGrouping::Community - b.trigger = Badge::Trigger::None - b.auto_revoke = false - b.system = true +[ + [Badge::OutOfLove, "Out of Love", BadgeType::Bronze, 1], + [Badge::MyCupRunnethOver, "My Cup Runneth Over", BadgeType::Silver, 5], + [Badge::CrazyInLove, "Crazy in Love", BadgeType::Gold, 20], +].each do |spec| + id, name, level, count = spec + Badge.seed do |b| + b.id = id + b.name = name + b.default_name = name + b.default_icon = "fa-heart" + b.badge_type_id = level + b.query = Badge::Queries.like_rate_limit(count) + b.default_badge_grouping_id = BadgeGrouping::Community + b.trigger = Badge::Trigger::None + b.auto_revoke = false + b.system = true + end end + Badge.where("NOT system AND id < 100").each do |badge| new_id = [Badge.maximum(:id) + 1, 100].max old_id = badge.id