Stop caching threads — YAGNI

This commit is contained in:
Jose Farias
2024-10-12 23:23:12 -06:00
parent f92d361b14
commit 1d6acb6119
19 changed files with 10 additions and 75 deletions
-1
View File
@@ -8,7 +8,6 @@ gem "importmap-rails"
gem "propshaft"
gem "stimulus-rails"
gem "turbo-rails"
gem "local_time"
# Deployment and drivers
gem "bootsnap", require: false
-2
View File
@@ -145,7 +145,6 @@ GEM
reline (>= 0.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
local_time (3.0.2)
logger (1.6.1)
loofah (2.22.0)
crass (~> 1.0.2)
@@ -327,7 +326,6 @@ DEPENDENCIES
capybara
debug
importmap-rails
local_time
propshaft
puma (>= 5.0)
rails!
-1
View File
@@ -1,4 +1,3 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "initializers"
import "controllers"
@@ -1,5 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { nextFrame } from "helpers"
import { nextFrame } from "helpers/timing_helpers"
export default class extends Controller {
static classes = [ "play" ]
@@ -1,5 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { debounce } from "helpers"
import { debounce } from "helpers/timing_helpers"
export default class extends Controller {
static targets = [ "list" ]
@@ -1,13 +0,0 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static classes = [ "myComment" ]
connect() {
this.#myComments.forEach(comment => comment.classList.add(this.myCommentClass))
}
get #myComments() {
return this.element.querySelectorAll(`.comment[data-creator-id='${Current.user.id}']`)
}
}
-1
View File
@@ -1 +0,0 @@
export * from "helpers/timing_helpers"
-15
View File
@@ -1,15 +0,0 @@
class Current {
get user() {
const currentUserId = this.#extractContentFromMetaTag("current-user-id")
if (currentUserId) {
return { id: parseInt(currentUserId) }
}
}
#extractContentFromMetaTag(name) {
return document.head.querySelector(`meta[name="${name}"]`)?.getAttribute("content")
}
}
window.Current = new Current()
-2
View File
@@ -1,2 +0,0 @@
import "initializers/current"
import "initializers/local_time"
@@ -1,2 +0,0 @@
import LocalTime from "local-time"
LocalTime.start()
-4
View File
@@ -13,10 +13,6 @@ class Bubble::Thread
"bubbles/threads/thread"
end
def cache_key
ActiveSupport::Cache.expand_cache_key bubble, :thread
end
private
delegate :events, :comments, to: :bubble, private: true
+3 -7
View File
@@ -13,14 +13,10 @@ class Bubble::Thread::Rollup
"bubbles/threads/rollup"
end
def cache_key
ActiveSupport::Cache.expand_cache_key [ thread, entries.first, entries.last ], "rollup"
end
private
attr_reader :thread, :entries, :first_position
delegate :local_time_ago, to: "ApplicationController.helpers", private: true
delegate :time_ago_in_words, to: "ApplicationController.helpers", private: true
def first_position?
first_position
@@ -47,10 +43,10 @@ class Bubble::Thread::Rollup
def summarize(entry, chunk_size)
case entry.action
when "created"
"added by #{entry.creator.name} #{local_time_ago(entry.created_at)}"
"added by #{entry.creator.name} #{time_ago_in_words(entry.created_at)} ago"
when "assigned"
summary = "assigned to #{entry.assignee_names.to_sentence}"
summary += " #{local_time_ago(entry.created_at)}" unless first_position?
summary += " #{time_ago_in_words(entry.created_at)} ago" unless first_position?
summary
when "boosted"
"#{entry.creator.name} +#{chunk_size}"
@@ -1,3 +0,0 @@
<%# Template Dependency: comments/comment %>
<%# Template Dependency: bubbles/threads/rollup %>
<%= render entry %>
+1 -1
View File
@@ -1,3 +1,3 @@
<div class="comment--upvotes flex-inline flex-wrap align-start fill-white border-radius center position-relative">
<%= rollup.body.html_safe %>
<%= rollup.body %>
</div>
+2 -9
View File
@@ -1,13 +1,6 @@
<% bubble = thread.bubble %>
<section id="<%= dom_id(bubble, :thread) %>"
class="comments align-center center borderless margin flex flex-column gap-half"
style="--bubble-color: <%= bubble.color %>;"
data-controller="thread"
data-thread-my-comment-class="comment--mine">
<% cache thread do %>
<%= render partial: "bubbles/threads/entry", collection: thread.entries, cache: true %>
<% end %>
<section id="<%= dom_id(bubble, :thread) %>" class="comments align-center center borderless margin flex flex-column gap-half" style="--bubble-color: <%= bubble.color %>;">
<%= render thread.entries %>
<%= render "comments/new", bubble: bubble %>
</section>
+2 -2
View File
@@ -1,4 +1,4 @@
<div id="<%= dom_id(comment) %>" class="comment flex align-start full-width" data-creator-id="<%= comment.creator.id %>">
<%= tag.div id: dom_id(comment), class: [ "comment flex align-start full-width", { "comment--mine": Current.user == comment.creator } ] do %>
<figure class="comment__avatar flex-item-no-shrink">
<%= avatar_tag comment.creator, loading: :lazy %>
</figure>
@@ -16,4 +16,4 @@
<%= simple_format comment.body %>
</div>
</div>
</div>
<% end %>
-4
View File
@@ -9,10 +9,6 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<% if Current.user %>
<meta name="current-user-id" content="<%= Current.user.id %>">
<% end %>
<%= yield :head %>
<%= stylesheet_link_tag :all, "data-turbo-track": "reload" %>
-2
View File
@@ -4,8 +4,6 @@ pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin "local-time" # @3.0.2
pin_all_from "app/javascript/initializers", under: "initializers"
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/helpers", under: "helpers"
File diff suppressed because one or more lines are too long