mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Revert "Revert "PERF: optimise query that gathers topic tracking state""
This reverts commit 909be09f1a.
This commit is contained in:
@@ -20,7 +20,7 @@ describe TopicTrackingState do
|
||||
user = Fabricate(:user)
|
||||
post
|
||||
|
||||
report = TopicTrackingState.report([user.id])
|
||||
report = TopicTrackingState.report(user.id)
|
||||
expect(report.length).to eq(1)
|
||||
|
||||
CategoryUser.create!(user_id: user.id,
|
||||
@@ -30,22 +30,23 @@ describe TopicTrackingState do
|
||||
|
||||
create_post(topic_id: post.topic_id)
|
||||
|
||||
report = TopicTrackingState.report([user.id])
|
||||
report = TopicTrackingState.report(user.id)
|
||||
expect(report.length).to eq(0)
|
||||
|
||||
TopicUser.create!(user_id: user.id, topic_id: post.topic_id, last_read_post_number: 1, notification_level: 3)
|
||||
|
||||
report = TopicTrackingState.report([user.id])
|
||||
expect(report.length).to eq(1)
|
||||
report = TopicTrackingState.report(user.id)
|
||||
# no read state for muted categories, query is faster
|
||||
expect(report.length).to eq(0)
|
||||
end
|
||||
|
||||
it "correctly gets the tracking state" do
|
||||
report = TopicTrackingState.report([user.id])
|
||||
report = TopicTrackingState.report(user.id)
|
||||
expect(report.length).to eq(0)
|
||||
|
||||
post.topic.notifier.watch_topic!(post.topic.user_id)
|
||||
|
||||
report = TopicTrackingState.report([user.id])
|
||||
report = TopicTrackingState.report(user.id)
|
||||
|
||||
expect(report.length).to eq(1)
|
||||
row = report[0]
|
||||
@@ -56,15 +57,18 @@ describe TopicTrackingState do
|
||||
expect(row.user_id).to eq(user.id)
|
||||
|
||||
# lets not leak out random users
|
||||
expect(TopicTrackingState.report([post.user_id])).to be_empty
|
||||
expect(TopicTrackingState.report(post.user_id)).to be_empty
|
||||
|
||||
# lets not return anything if we scope on non-existing topic
|
||||
expect(TopicTrackingState.report([user.id], post.topic_id + 1)).to be_empty
|
||||
expect(TopicTrackingState.report(user.id, post.topic_id + 1)).to be_empty
|
||||
|
||||
# when we reply the poster should have an unread row
|
||||
create_post(user: user, topic: post.topic)
|
||||
|
||||
report = TopicTrackingState.report([post.user_id, user.id])
|
||||
report = TopicTrackingState.report(user.id)
|
||||
expect(report.length).to eq(0)
|
||||
|
||||
report = TopicTrackingState.report(post.user_id)
|
||||
expect(report.length).to eq(1)
|
||||
|
||||
row = report[0]
|
||||
@@ -80,6 +84,7 @@ describe TopicTrackingState do
|
||||
post.topic.category_id = category.id
|
||||
post.topic.save
|
||||
|
||||
expect(TopicTrackingState.report([post.user_id, user.id]).count).to eq(0)
|
||||
expect(TopicTrackingState.report(post.user_id)).to be_empty
|
||||
expect(TopicTrackingState.report(user.id)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user