mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-07 14:22:12 +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
|
class Rewind::Action::CreatePostsCountReport < Service::ActionBase
|
||||||
option :params
|
option :params
|
||||||
option :guardian
|
option :guardian
|
||||||
|
option :date
|
||||||
|
option :user
|
||||||
|
|
||||||
delegate :username, :year, to: :params, private: true
|
delegate :username, :year, to: :params, private: true
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
p date
|
||||||
|
p user
|
||||||
|
p guardian
|
||||||
|
p username
|
||||||
|
p year
|
||||||
|
p params
|
||||||
|
|
||||||
{ data: { count: 5 }, identifier: "posts-count-report" }
|
{ data: { count: 5 }, identifier: "posts-count-report" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -35,16 +35,26 @@ module DiscourseRewind
|
|||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
model :user
|
||||||
|
model :date
|
||||||
model :reports
|
model :reports
|
||||||
|
|
||||||
private
|
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}"
|
key = "rewind:#{params.username}:#{params.year}"
|
||||||
reports = Discourse.redis.get(key)
|
reports = Discourse.redis.get(key)
|
||||||
|
|
||||||
if Rails.env.development? || !reports
|
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))
|
Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports))
|
||||||
else
|
else
|
||||||
reports = MultiJson.load(reports, symbolize_keys: true)
|
reports = MultiJson.load(reports, symbolize_keys: true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user