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
36 changes: 21 additions & 15 deletions src/renderer/routes/github/LoginWithDeviceFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,31 @@ export const GitHubLoginWithDeviceFlowRoute: FC = () => {
const startPolling = async () => {
setIsPolling(true);

try {
while (isActive && Date.now() < session.expiresAt) {
const token = await loginWithDeviceFlowPoll(forge, session);

if (token && isActive) {
await loginWithDeviceFlowComplete(forge, token, session.hostname);
navigate('/');
return;
const poll = async (): Promise<void> => {
if (!isActive || Date.now() >= session.expiresAt) {
if (isActive) {
setError('Device code expired. Please start again.');
}

const intervalMs = Math.max(5000, session.intervalSeconds * 1000);
await new Promise((resolve) => {
timeoutId = setTimeout(resolve, intervalMs);
});
return;
}

if (isActive) {
setError('Device code expired. Please start again.');
const token = await loginWithDeviceFlowPoll(forge, session);

if (token && isActive) {
await loginWithDeviceFlowComplete(forge, token, session.hostname);
navigate('/');
return;
}

const intervalMs = Math.max(5000, session.intervalSeconds * 1000);
await new Promise((resolve) => {
timeoutId = setTimeout(resolve, intervalMs);
});
await poll();
};

try {
await poll();
} catch (err) {
if (isActive) {
rendererLogError('LoginWithDeviceFlow', 'Failed to poll device flow', toError(err));
Expand Down
35 changes: 21 additions & 14 deletions src/renderer/utils/forges/github/enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,35 @@ export async function enrichGitHubNotifications(
async function fetchInBatches(
notifications: RawGitifyNotification[],
): Promise<Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>> {
const merged = new Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>();
const supportedNotifications = notifications.filter(
(notification) => createNotificationHandler(notification).supportsMergedQueryEnrichment,
);

const batchSize = GITHUB_API_MERGE_BATCH_SIZE;

const batches: RawGitifyNotification[][] = [];
for (let start = 0; start < supportedNotifications.length; start += batchSize) {
const batchIndex = Math.floor(start / batchSize) + 1;
const slice = supportedNotifications.slice(start, start + batchSize);
batches.push(supportedNotifications.slice(start, start + batchSize));
}

try {
const batchResults = await fetchNotificationDetailsForList(slice);
for (const [notification, repository] of batchResults) {
merged.set(notification, repository);
const batchResults = await Promise.all(
batches.map(async (slice, index) => {
try {
return await fetchNotificationDetailsForList(slice);
} catch (err) {
rendererLogError(
'enrichGitHubNotifications',
`Failed to fetch merged notification details for batch ${index + 1}`,
toError(err),
);
return new Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>();
}
} catch (err) {
rendererLogError(
'enrichGitHubNotifications',
`Failed to fetch merged notification details for batch ${batchIndex}`,
toError(err),
);
}),
);

const merged = new Map<RawGitifyNotification, FetchMergedDetailsTemplateQuery['repository']>();
for (const results of batchResults) {
for (const [notification, repository] of results) {
merged.set(notification, repository);
}
}

Expand Down
Loading