Skip to content

Commit

Permalink
fix[Op#40437]: remove support for emoji reactions timeslicing
Browse files Browse the repository at this point in the history
Emoji Reactions should always be returned in their current state, timeslicing will yield incorrect results.
At any given time, we ONLY need to know what reactions a Journal has. Further, EmojiReactions are never updated, rather created
and destroyed.

Retain timeslicing only for the journal render- where that is relevant to find updated journals
  • Loading branch information
akabiru committed Oct 25, 2024
1 parent fb419dd commit 232df80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
3 changes: 1 addition & 2 deletions app/controllers/work_packages/activities_tab_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ def generate_time_based_update_streams(last_update_timestamp)
end

grouped_emoji_reactions = Journal.grouped_emoji_reactions_by_reactable(
reactable_id: journals.pluck(:id),
reactable_type: "Journal", last_updated_at: last_update_timestamp
reactable_id: journals.pluck(:id), reactable_type: "Journal"
)

rerender_updated_journals(journals, last_update_timestamp, grouped_emoji_reactions)
Expand Down
16 changes: 6 additions & 10 deletions app/models/concerns/reactable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def grouped_journal_emoji_reactions(journal)
grouped_emoji_reactions_by_reactable(reactable_id: journal.id, reactable_type: "Journal")
end

def grouped_work_package_journals_emoji_reactions(work_package, last_updated_at: nil)
grouped_emoji_reactions_by_reactable(reactable_id: work_package.journal_ids, reactable_type: "Journal", last_updated_at:)
def grouped_work_package_journals_emoji_reactions(work_package)
grouped_emoji_reactions_by_reactable(reactable_id: work_package.journal_ids, reactable_type: "Journal")
end

def grouped_emoji_reactions_by_reactable(reactable_id:, reactable_type:, last_updated_at: nil)
grouped_emoji_reactions(reactable_id:, reactable_type:, last_updated_at:).each_with_object({}) do |row, hash|
def grouped_emoji_reactions_by_reactable(reactable_id:, reactable_type:)
grouped_emoji_reactions(reactable_id:, reactable_type:).each_with_object({}) do |row, hash|
hash[row.reactable_id] ||= {}
hash[row.reactable_id][row.reaction.to_sym] = {
count: row.count,
Expand All @@ -52,15 +52,11 @@ def grouped_emoji_reactions_by_reactable(reactable_id:, reactable_type:, last_up
end
end

def grouped_emoji_reactions(reactable_id:, reactable_type:, last_updated_at: nil)
query = EmojiReaction
def grouped_emoji_reactions(reactable_id:, reactable_type:)
EmojiReaction
.select(emoji_reactions_group_selection_sql)
.joins(:user)
.where(reactable_id:, reactable_type:)

query = query.where("emoji_reactions.updated_at > ?", last_updated_at) if last_updated_at

query
.group("emoji_reactions.reactable_id, emoji_reactions.reaction")
.order("first_created_at ASC")
end
Expand Down
16 changes: 0 additions & 16 deletions spec/models/concerns/reactable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,6 @@
)
end

context "when last_updated_at is set" do
it "returns grouped emoji reactions for work package journals that were updated after last_updated_at" do
wp_journal1.update!(updated_at: 1.day.ago)
result = Journal.grouped_work_package_journals_emoji_reactions(work_package, last_updated_at: wp_journal2.updated_at)

expect(result).to eq(
wp_journal2.id => {
thumbs_down: {
count: 1,
users: [{ id: user2.id, name: user2.name }]
}
}
)
end
end

context "when no reactions exist" do
it "returns an empty hash" do
work_package = build_stubbed(:work_package)
Expand Down

0 comments on commit 232df80

Please sign in to comment.