Compare commits
11
Commits
long-words
...
cache
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b1af6f717 | ||
|
|
19af3cb107 | ||
|
|
7cc39605f5 | ||
|
|
fed8205a64 | ||
|
|
d669a39a00 | ||
|
|
6a55f56b91 | ||
|
|
17e30c3933 | ||
|
|
ef21ee6b35 | ||
|
|
b358456b65 | ||
|
|
472783d1c1 | ||
|
|
2bb1072d29 |
@@ -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
|
||||
|
||||
@@ -3,7 +3,19 @@
|
||||
# Topics visited grouped by category
|
||||
module DiscourseRewind
|
||||
class Rewind::Action::FavoriteCategories < Rewind::Action::BaseReport
|
||||
FakeData = {
|
||||
data: [
|
||||
{ category_id: 1, name: "cats" },
|
||||
{ category_id: 2, name: "dogs" },
|
||||
{ category_id: 3, name: "countries" },
|
||||
{ category_id: 4, name: "management" },
|
||||
{ category_id: 5, name: "things" },
|
||||
],
|
||||
identifier: "favorite-categories",
|
||||
}
|
||||
def call
|
||||
return FakeData if Rails.env.development?
|
||||
|
||||
favorite_categories =
|
||||
TopicViewItem
|
||||
.joins(:topic)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -38,82 +38,102 @@ module DiscourseRewind
|
||||
"The Hunger Games" => {
|
||||
reading_time: 19_740,
|
||||
isbn: "978-0439023481",
|
||||
series: false,
|
||||
},
|
||||
"The Metamorphosis" => {
|
||||
reading_time: 3120,
|
||||
isbn: "978-0553213690",
|
||||
series: false,
|
||||
},
|
||||
"To Kill a Mockingbird" => {
|
||||
reading_time: 22_800,
|
||||
isbn: "978-0061120084",
|
||||
series: false,
|
||||
},
|
||||
"Pride and Prejudice" => {
|
||||
reading_time: 25_200,
|
||||
isbn: "978-1503290563",
|
||||
series: false,
|
||||
},
|
||||
"1984" => {
|
||||
reading_time: 16_800,
|
||||
isbn: "978-0451524935",
|
||||
series: false,
|
||||
},
|
||||
"The Lord of the Rings" => {
|
||||
reading_time: 108_000,
|
||||
isbn: "978-0544003415",
|
||||
series: true,
|
||||
},
|
||||
"Harry Potter and the Sorcerer's Stone" => {
|
||||
reading_time: 24_600,
|
||||
isbn: "978-0590353427",
|
||||
series: true,
|
||||
},
|
||||
"The Great Gatsby" => {
|
||||
reading_time: 12_600,
|
||||
isbn: "978-0743273565",
|
||||
series: false,
|
||||
},
|
||||
"The Little Prince" => {
|
||||
reading_time: 5400,
|
||||
isbn: "978-0156012195",
|
||||
series: false,
|
||||
},
|
||||
"Animal Farm" => {
|
||||
reading_time: 7200,
|
||||
isbn: "978-0451526342",
|
||||
series: false,
|
||||
},
|
||||
"The Catcher in the Rye" => {
|
||||
reading_time: 18_000,
|
||||
isbn: "978-0316769488",
|
||||
series: false,
|
||||
},
|
||||
"Jane Eyre" => {
|
||||
reading_time: 34_200,
|
||||
isbn: "978-0141441146",
|
||||
series: false,
|
||||
},
|
||||
"Fahrenheit 451" => {
|
||||
reading_time: 15_000,
|
||||
isbn: "978-1451673319",
|
||||
series: false,
|
||||
},
|
||||
"The Hobbit" => {
|
||||
reading_time: 27_000,
|
||||
isbn: "978-0547928227",
|
||||
series: false,
|
||||
},
|
||||
"The Da Vinci Code" => {
|
||||
reading_time: 37_800,
|
||||
isbn: "978-0307474278",
|
||||
series: false,
|
||||
},
|
||||
"Little Women" => {
|
||||
reading_time: 30_000,
|
||||
isbn: "978-0147514011",
|
||||
series: false,
|
||||
},
|
||||
"One Hundred Years of Solitude" => {
|
||||
reading_time: 46_800,
|
||||
isbn: "978-0060883287",
|
||||
series: false,
|
||||
},
|
||||
"And Then There Were None" => {
|
||||
reading_time: 16_200,
|
||||
isbn: "978-0062073488",
|
||||
series: false,
|
||||
},
|
||||
"The Alchemist" => {
|
||||
reading_time: 10_800,
|
||||
isbn: "978-0061122415",
|
||||
series: false,
|
||||
},
|
||||
"The Hitchhiker's Guide to the Galaxy" => {
|
||||
reading_time: 12_600,
|
||||
isbn: "978-0345391803",
|
||||
series: false,
|
||||
},
|
||||
"The Complete works of Shakespeare" => {
|
||||
reading_time: 180_000,
|
||||
@@ -170,7 +190,11 @@ module DiscourseRewind
|
||||
book_title =
|
||||
books.group_by { |book| book }.transform_values(&:count).max_by { |_, count| count }.first
|
||||
|
||||
{ title: book_title, isbn: popular_books[book_title][:isbn] }
|
||||
{
|
||||
title: book_title,
|
||||
isbn: popular_books[book_title][:isbn],
|
||||
series: popular_books[book_title][:series],
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -10,12 +10,12 @@ const FavoriteCategories = <template>
|
||||
}}</h2>
|
||||
<div class="rewind-report-container">
|
||||
{{#each @report.data as |data|}}
|
||||
<div class="rewind-card">
|
||||
<a
|
||||
<a href={{concat "/c/-/" data.category_id}} class="rewind-card">
|
||||
<p
|
||||
class="favorite-categories__category"
|
||||
href={{concat "/c/-/" data.category_id}}
|
||||
>{{data.name}}</a>
|
||||
</div>
|
||||
>{{data.name}}</p>
|
||||
</a>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user