Files
archived-hc-harbor/app/services/leaderboard_service.rb
Echo 810f09828c bug fixes (#630)
* fix on old repos

* clean up broken leaderboards

* Update app/jobs/sync_repo_metadata_job.rb

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* remove broken lb logic

* Update db/migrate/20251116045400_clean_up_weekly_leaderboards.rb

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 00:23:42 -05:00

26 lines
743 B
Ruby

class LeaderboardService
def self.get(period: :daily, date: Date.current)
new.get(period: period, date: date)
end
def get(period: :daily, date: Date.current)
date = Date.current if date.blank?
date = LeaderboardDateRange.normalize_date(date, period)
key = LeaderboardCache.global_key(period, date)
board = LeaderboardCache.read(key)
return board if board.present?
board = ::Leaderboard.where.not(finished_generating_at: nil)
.find_by(start_date: date, period_type: period, timezone_utc_offset: nil, deleted_at: nil)
if board.present?
LeaderboardCache.write(key, board)
return board
end
::LeaderboardUpdateJob.perform_later(period, date)
nil
end
end