mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
* 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>
26 lines
743 B
Ruby
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
|