2021-10-26 18:42:35 +08:00
|
|
|
class ProjectRankController < ApplicationController
|
|
|
|
# 根据时间获取热门项目
|
2023-04-15 15:12:44 +08:00
|
|
|
def index
|
|
|
|
limit = 9
|
|
|
|
limit = params[:limit].to_i - 1 if params[:limit].present?
|
|
|
|
limit = 99 if limit > 99
|
2023-01-04 11:38:07 +08:00
|
|
|
$redis_cache.zunionstore("recent-days-project-rank-#{time}", get_timeable_key_names)
|
2021-11-02 09:51:38 +08:00
|
|
|
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
|
2023-01-04 11:38:07 +08:00
|
|
|
$redis_cache.zrem("recent-days-project-rank-#{time}", deleted_data) unless deleted_data.blank?
|
2023-04-15 15:12:44 +08:00
|
|
|
@project_rank = $redis_cache.zrevrange("recent-days-project-rank-#{time}", 0, limit, withscores: true)
|
2021-10-26 18:42:35 +08:00
|
|
|
rescue Exception => e
|
2021-11-01 16:20:52 +08:00
|
|
|
@project_rank = []
|
2021-10-26 18:42:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
# 默认显示7天的
|
|
|
|
def time
|
|
|
|
params.fetch(:time, 7).to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_timeable_key_names
|
|
|
|
names_array = []
|
|
|
|
(0...time).to_a.each do |i|
|
|
|
|
date_time_string = (Date.today - i.days).to_s
|
|
|
|
names_array << "v2-project-rank-#{date_time_string}"
|
|
|
|
end
|
|
|
|
names_array
|
|
|
|
end
|
|
|
|
end
|