mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-07 22:32:11 +00:00
pre-fetch user/date for each report
This commit is contained in:
parent
925cfeffd1
commit
52acb18ff0
@ -4,10 +4,19 @@ module DiscourseRewind
|
||||
class Rewind::Action::CreatePostsCountReport < Service::ActionBase
|
||||
option :params
|
||||
option :guardian
|
||||
option :date
|
||||
option :user
|
||||
|
||||
delegate :username, :year, to: :params, private: true
|
||||
|
||||
def call
|
||||
p date
|
||||
p user
|
||||
p guardian
|
||||
p username
|
||||
p year
|
||||
p params
|
||||
|
||||
{ data: { count: 5 }, identifier: "posts-count-report" }
|
||||
end
|
||||
end
|
||||
|
@ -35,16 +35,26 @@ module DiscourseRewind
|
||||
validates :username, presence: true
|
||||
end
|
||||
|
||||
model :user
|
||||
model :date
|
||||
model :reports
|
||||
|
||||
private
|
||||
|
||||
def fetch_reports(params:, guardian:)
|
||||
def fetch_user(params:)
|
||||
User.find_by_username(params.username)
|
||||
end
|
||||
|
||||
def fetch_date(params:)
|
||||
Date.new(params.year).all_year
|
||||
end
|
||||
|
||||
def fetch_reports(params:, date:, user:, guardian:)
|
||||
key = "rewind:#{params.username}:#{params.year}"
|
||||
reports = Discourse.redis.get(key)
|
||||
|
||||
if Rails.env.development? || !reports
|
||||
reports = REPORTS.map { |report| report.call(params:, guardian:) }
|
||||
reports = REPORTS.map { |report| report.call(params:, date:, user:, guardian:) }
|
||||
Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports))
|
||||
else
|
||||
reports = MultiJson.load(reports, symbolize_keys: true)
|
||||
|
Loading…
x
Reference in New Issue
Block a user