diff --git a/app/services/discourse_rewind/rewind/action/activity_calendar.rb b/app/services/discourse_rewind/rewind/action/activity_calendar.rb index 6fd1fda..56193a7 100644 --- a/app/services/discourse_rewind/rewind/action/activity_calendar.rb +++ b/app/services/discourse_rewind/rewind/action/activity_calendar.rb @@ -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 diff --git a/app/services/discourse_rewind/rewind/action/reactions.rb b/app/services/discourse_rewind/rewind/action/reactions.rb index 987cd51..1b6d74e 100644 --- a/app/services/discourse_rewind/rewind/action/reactions.rb +++ b/app/services/discourse_rewind/rewind/action/reactions.rb @@ -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", diff --git a/app/services/discourse_rewind/rewind/fetch.rb b/app/services/discourse_rewind/rewind/fetch.rb index 082bfb5..dd8f9ed 100644 --- a/app/services/discourse_rewind/rewind/fetch.rb +++ b/app/services/discourse_rewind/rewind/fetch.rb @@ -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 - 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 + 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, reports.to_json) + else + reports = JSON.parse(cached_reports, symbolize_names: true) + end reports end