Skip to content

Commit b8b4140

Browse files
authored
Merge pull request #9536 from Fryguy/remove_extra_notifications_query
Use the count directly to avoid 2 notifications calls per page
2 parents 20738b2 + 5eecc1f commit b8b4140

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

app/javascript/notifications/backend.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,17 @@ export function convert(resource) {
2424
}
2525

2626
export function load(useLimit) {
27-
const promises = [];
2827
const limitFragment = useLimit ? `&limit=${maxNotifications}` : '';
2928

30-
promises.push(API.get(`/api/notifications?expand=resources&attributes=details&sort_by=id&sort_order=desc${limitFragment}`)
29+
return API.get(`/api/notifications?expand=resources&attributes=details&sort_by=id&sort_order=desc${limitFragment}`)
3130
.then((data) => {
3231
const notifications = data.resources.map(convert);
3332

3433
return {
3534
notifications,
36-
subcount: data.subcount,
35+
subcount: data.count
3736
};
38-
}));
39-
40-
if (useLimit) {
41-
// get real subcount
42-
promises.push(API.get('/api/notifications'));
43-
}
44-
45-
return Promise.all(promises).then(([{ notifications, subcount }, meta]) => ({
46-
notifications,
47-
subcount: meta ? meta.subcount : subcount,
48-
}));
37+
});
4938
}
5039

5140
const bulkAction = (action) => (notifications) => API.post(`/api/notifications/`, {

0 commit comments

Comments
 (0)