mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Minor but we can just pass a hash to where.
```
Warming up --------------------------------------
4 x .where 1.040k i/100ms
1 x .where 1.677k i/100ms
Calculating -------------------------------------
4 x .where 10.321k (± 5.2%) i/s - 52.000k in
5.053803s
1 x .where 17.117k (± 3.8%) i/s - 85.527k in
5.004107s
Comparison:
1 x .where: 17117.1 i/s
4 x .where: 10321.3 i/s - 1.66x slower
```
This commit is contained in:
@@ -59,18 +59,22 @@ class Notification < ActiveRecord::Base
|
||||
|
||||
def self.mark_posts_read(user, topic_id, post_numbers)
|
||||
Notification
|
||||
.where(user_id: user.id)
|
||||
.where(topic_id: topic_id)
|
||||
.where(post_number: post_numbers)
|
||||
.where(read: false)
|
||||
.where(
|
||||
user_id: user.id,
|
||||
topic_id: topic_id,
|
||||
post_number: post_numbers,
|
||||
read: false
|
||||
)
|
||||
.update_all(read: true)
|
||||
end
|
||||
|
||||
def self.read(user, notification_ids)
|
||||
Notification
|
||||
.where(id: notification_ids)
|
||||
.where(user_id: user.id)
|
||||
.where(read: false)
|
||||
.where(
|
||||
id: notification_ids,
|
||||
user_id: user.id,
|
||||
read: false
|
||||
)
|
||||
.update_all(read: true)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user