mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-03 04:08:06 -06:00
[chore/performance] Avoid unnecessary "uncached" queries (#3265)
* [chore/performance] Avoid unnecessary "uncached" queries * go fmt
This commit is contained in:
parent
f924297af1
commit
25a815a8a4
17 changed files with 149 additions and 21 deletions
|
|
@ -107,13 +107,15 @@ func (n *notificationDB) GetNotificationsByIDs(ctx context.Context, ids []string
|
|||
notifs, err := n.state.Caches.DB.Notification.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Notification, error) {
|
||||
// Skip query if everything was cached.
|
||||
if len(uncached) == 0 {
|
||||
// Avoid querying
|
||||
// if none uncached.
|
||||
count := len(uncached)
|
||||
if count == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Preallocate expected length of uncached notifications.
|
||||
notifs := make([]*gtsmodel.Notification, 0, len(uncached))
|
||||
notifs := make([]*gtsmodel.Notification, 0, count)
|
||||
|
||||
// Perform database query scanning
|
||||
// the remaining (uncached) IDs.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue