Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/renderer/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const Constants = {

GITHUB_API_BASE_URL: 'https://api.github.com',
GITHUB_API_GRAPHQL_URL: 'https://api.github.com/graphql',
GITHUB_API_MERGE_BATCH_SIZE: 100,

// Emojis for different states and events
EMOJIS: {
Expand Down
12 changes: 9 additions & 3 deletions src/renderer/utils/forges/github/enrich.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Constants } from '../../../constants';

import type { GitifySubject, RawGitifyNotification, SettingsState } from '../../../types';

import { rendererLogError, rendererLogWarn, toError } from '../../core/logger';
import { fetchNotificationDetailsForList } from './client';
import type { FetchMergedDetailsTemplateQuery } from './graphql/generated/graphql';
import { createNotificationHandler } from './handlers';

/**
* Maximum number of notifications batched into a single merged GraphQL query
* by `enrichGitHubNotifications`. GitHub's GraphQL alias cap is well above
* 100; this is a conservative ceiling that keeps individual responses small
* and parseable.
*/
export const GITHUB_API_MERGE_BATCH_SIZE = 100;

/**
* Enrich GitHub notifications with additional subject details (state, user,
* comment count, labels, etc.) by issuing a single batched GraphQL query
Expand All @@ -33,7 +39,7 @@ async function fetchInBatches(
): Promise<Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>> {
const merged = new Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>();

const batchSize = Constants.GITHUB_API_MERGE_BATCH_SIZE;
const batchSize = GITHUB_API_MERGE_BATCH_SIZE;

for (let start = 0; start < notifications.length; start += batchSize) {
const batchIndex = Math.floor(start / batchSize) + 1;
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/utils/notifications/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
} from '../../__mocks__/notifications-mocks';
import { mockSettings } from '../../__mocks__/state-mocks';

import { Constants } from '../../constants';

import {
type AccountNotifications,
type GitifyNotification,
Expand All @@ -20,6 +18,7 @@ import {
} from '../../types';

import * as apiClient from '../forges/github/client';
import { GITHUB_API_MERGE_BATCH_SIZE } from '../forges/github/enrich';
import {
enrichNotifications,
getNotificationCount,
Expand Down Expand Up @@ -141,7 +140,7 @@ describe('renderer/utils/notifications/notifications.ts', () => {
.spyOn(apiClient, 'fetchNotificationDetailsForList')
.mockResolvedValue(new Map());

const notificationCount = Constants.GITHUB_API_MERGE_BATCH_SIZE * 2.5;
const notificationCount = GITHUB_API_MERGE_BATCH_SIZE * 2.5;
const notifications = Array.from({ length: notificationCount }, (_, i) =>
mockPartialGitifyNotification({
title: `Notification ${i}`,
Expand All @@ -162,10 +161,10 @@ describe('renderer/utils/notifications/notifications.ts', () => {

// Verify batch sizes
expect(fetchNotificationDetailsForListSpy.mock.calls[0][0]).toHaveLength(
Constants.GITHUB_API_MERGE_BATCH_SIZE,
GITHUB_API_MERGE_BATCH_SIZE,
);
expect(fetchNotificationDetailsForListSpy.mock.calls[1][0]).toHaveLength(
Constants.GITHUB_API_MERGE_BATCH_SIZE,
GITHUB_API_MERGE_BATCH_SIZE,
);
expect(fetchNotificationDetailsForListSpy.mock.calls[2][0]).toHaveLength(50);
});
Expand Down
Loading