feat: implement batch unread counts for notifications to reduce API calls and improve performance

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-03-10 01:26:37 -07:00
parent 7362da52d3
commit 403097646d
18 changed files with 450 additions and 51 deletions

View file

@ -1,8 +1,10 @@
import {
type GetBatchUnreadCountResponse,
type GetNotificationsRequest,
type GetNotificationsResponse,
type GetSourceTypesResponse,
type GetUnreadCountResponse,
getBatchUnreadCountResponse,
getNotificationsRequest,
getNotificationsResponse,
getSourceTypesResponse,
@ -149,6 +151,25 @@ class NotificationsApiService {
getUnreadCountResponse
);
};
/**
* Get unread counts for all categories in a single request.
* Replaces 2 separate getUnreadCount calls (comments + status).
*/
getBatchUnreadCounts = async (
searchSpaceId?: number
): Promise<GetBatchUnreadCountResponse> => {
const params = new URLSearchParams();
if (searchSpaceId !== undefined) {
params.append("search_space_id", String(searchSpaceId));
}
const queryString = params.toString();
return baseApiService.get(
`/api/v1/notifications/unread-counts-batch${queryString ? `?${queryString}` : ""}`,
getBatchUnreadCountResponse
);
};
}
export const notificationsApiService = new NotificationsApiService();