mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-07 06:12:22 +00:00
cache fix
This commit is contained in:
parent
19af3cb107
commit
4b1af6f717
@ -7,7 +7,7 @@ module DiscourseRewind
|
||||
FakeData = {
|
||||
data:
|
||||
(Date.new(2024, 1, 1)..Date.new(2024, 12, 31)).map do |date|
|
||||
{ date:, post_count: rand(0..20), visited: false }
|
||||
{ date: date.strftime("%Y-%m-%d"), post_count: rand(0..20), visited: false }
|
||||
end,
|
||||
identifier: "activity-calendar",
|
||||
}
|
||||
@ -33,7 +33,13 @@ module DiscourseRewind
|
||||
)
|
||||
.group("generate_series, user_visits.id")
|
||||
.order("generate_series")
|
||||
.map { |row| { date: row.date, post_count: row.post_count, visited: row.visited } }
|
||||
.map do |row|
|
||||
{
|
||||
date: row.date.strftime("%Y-%m-%d"),
|
||||
post_count: row.post_count,
|
||||
visited: row.visited,
|
||||
}
|
||||
end
|
||||
|
||||
{ data: calendar, identifier: "activity-calendar" }
|
||||
end
|
||||
|
@ -6,32 +6,32 @@ module DiscourseRewind
|
||||
FakeData = {
|
||||
data: {
|
||||
post_received_reactions: {
|
||||
"open_mouth" => 2,
|
||||
"cat" => 32,
|
||||
"dog" => 34,
|
||||
"heart" => 45,
|
||||
"grinning" => 82,
|
||||
open_mouth: 2,
|
||||
cat: 32,
|
||||
dog: 34,
|
||||
heart: 45,
|
||||
grinning: 82,
|
||||
},
|
||||
post_used_reactions: {
|
||||
"open_mouth" => 2,
|
||||
"cat" => 32,
|
||||
"dog" => 34,
|
||||
"heart" => 45,
|
||||
"grinning" => 82,
|
||||
open_mouth: 2,
|
||||
cat: 32,
|
||||
dog: 34,
|
||||
heart: 45,
|
||||
grinning: 82,
|
||||
},
|
||||
chat_used_reactions: {
|
||||
"open_mouth" => 2,
|
||||
"cat" => 32,
|
||||
"dog" => 34,
|
||||
"heart" => 45,
|
||||
"grinning" => 82,
|
||||
open_mouth: 2,
|
||||
cat: 32,
|
||||
dog: 34,
|
||||
heart: 45,
|
||||
grinning: 82,
|
||||
},
|
||||
chat_received_reactions: {
|
||||
"open_mouth" => 2,
|
||||
"cat" => 32,
|
||||
"dog" => 34,
|
||||
"heart" => 45,
|
||||
"grinning" => 82,
|
||||
open_mouth: 2,
|
||||
cat: 32,
|
||||
dog: 34,
|
||||
heart: 45,
|
||||
grinning: 82,
|
||||
},
|
||||
},
|
||||
identifier: "reactions",
|
||||
|
@ -51,19 +51,19 @@ module DiscourseRewind
|
||||
end
|
||||
|
||||
def fetch_reports(date:, user:, guardian:, year:)
|
||||
# key = "rewind:#{guardian.user.username}:#{year}"
|
||||
# reports = Discourse.redis.get(key)
|
||||
key = "rewind:#{guardian.user.id}:#{year}"
|
||||
cached_reports = Discourse.redis.get(key)
|
||||
|
||||
# if Rails.env.development? || !reports
|
||||
if !cached_reports
|
||||
reports =
|
||||
::DiscourseRewind::Rewind::Action::BaseReport
|
||||
.descendants
|
||||
.filter { _1.enabled? }
|
||||
.map { |report| report.call(date:, user:, guardian:) }
|
||||
# Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports))
|
||||
# else
|
||||
# reports = MultiJson.load(reports.compact, symbolize_keys: true)
|
||||
# end
|
||||
Discourse.redis.setex(key, CACHE_DURATION, reports.to_json)
|
||||
else
|
||||
reports = JSON.parse(cached_reports, symbolize_names: true)
|
||||
end
|
||||
|
||||
reports
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user