Merge #336: avoid rewriting already-unread room memberships

This commit is contained in:
GPT on behalf of DHH
2026-10-08 11:33:18 +02:00
3 changed files with 56 additions and 1 deletions
@@ -28,6 +28,23 @@ class Users::SidebarsControllerTest < ActionDispatch::IntegrationTest
assert_select ".unread", count: users(:david).memberships.reject { |m| m.room.direct? || !m.unread? }.count
end
test "a cached direct that is already unread still sorts by its latest message" do
room = rooms(:david_and_jason)
with_memory_cache do
travel_to 1.hour.ago do
room.messages.create! client_message_id: 998, body: "First", creator: users(:jason)
end
get user_sidebar_url
assert memberships(:david_david_and_jason).reload.unread?
room.messages.create! client_message_id: 999, body: "Second", creator: users(:jason)
get user_sidebar_url
assert_select "##{dom_id(room, :list)}[data-sorted-list-number=?]", room.reload.updated_at.to_fs(:epoch)
end
end
test "directs are ordered by room recency, not name" do
older = rooms(:david_and_jason)
newer = rooms(:david_and_kevin)
@@ -48,4 +65,23 @@ class Users::SidebarsControllerTest < ActionDispatch::IntegrationTest
assert positions.all?
assert_equal positions.sort, positions
end
private
def with_memory_cache
old_cache = Rails.cache
old_collection_cache = ActionView::PartialRenderer.collection_cache
old_controller_cache = Users::SidebarsController.cache_store
old_caching = Users::SidebarsController.perform_caching
Rails.cache = ActiveSupport::Cache::MemoryStore.new
ActionView::PartialRenderer.collection_cache = Rails.cache
Users::SidebarsController.cache_store = Rails.cache
Users::SidebarsController.perform_caching = true
yield
ensure
Rails.cache = old_cache
ActionView::PartialRenderer.collection_cache = old_collection_cache
Users::SidebarsController.cache_store = old_controller_cache
Users::SidebarsController.perform_caching = old_caching
end
end