Skip to content

Commit

Permalink
Made the suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushhunt committed Dec 2, 2024
1 parent 5c1b905 commit 7f532e1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
24 changes: 18 additions & 6 deletions apps/triggers/src/collaborator.status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export const publishContributorsTask = schedules.task({

let contributors = [];
let page = 1;

const MAX_PAGES = 10; // Limit total pages to prevent excessive API calls
try {
do {
if (page > MAX_PAGES) {
logger.warn(`Reached maximum page limit of ${MAX_PAGES}`);
break;
}
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/contributors?per_page=100&page=${page}`,
{
Expand All @@ -24,7 +28,11 @@ export const publishContributorsTask = schedules.task({
},
}
);

const rateLimit = response.headers.get('x-ratelimit-remaining');
if (rateLimit === '0') {
logger.error('GitHub API rate limit exceeded');
return;
}
if (!response.ok) {
logger.error(`GitHub API request failed with status ${response.status}`);
return;
Expand All @@ -38,7 +46,7 @@ export const publishContributorsTask = schedules.task({

contributors = contributors.concat(data);
page += 1;
} while (true);
} while (page <=MAX_PAGES);

// Filter out bots based on type or if 'bot' appears in their login
const filteredContributors = contributors.filter(
Expand All @@ -57,9 +65,13 @@ export const publishContributorsTask = schedules.task({

// Store data in Redis under a fixed key
const redisKey = 'contributors';
await cache.del(redisKey); // Clear existing data
await cache.rpush(redisKey, ...contributorData.map((c) => JSON.stringify(c)));

try {
await cache.del(redisKey); // Clear existing data
await cache.rpush(redisKey, ...contributorData.map((c) => JSON.stringify(c)));
} catch (error) {
logger.error('Failed to store contributors in Redis', { error });
throw error; // Re-throw to trigger task retry
}
logger.log('Published contributors data', { contributorData });
} catch (error) {
logger.error('Error fetching contributors from GitHub', { error });
Expand Down
2 changes: 0 additions & 2 deletions apps/www/app/(routes)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import ContributorsGridWrapper from "@/components/custom/ColloboratorGridWrapper";
import ContributorsGrid from "@/components/custom/Colloborators";
import DummyDataPage from "@/components/custom/Colloborators";
import {
SectionHeader,
SectionHeaderDescription,
Expand Down
17 changes: 0 additions & 17 deletions apps/www/app/api/getDummyData.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/www/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en" suppressHydrationWarning>

<PosthogProvider>
<body
className={` bg-background font-sans min-h-screen ${GeistSans.variable} antialiased`}
>
Expand All @@ -33,7 +33,7 @@ export default function RootLayout({
</ThemeProvider>
<Toaster />
</body>

</PosthogProvider>
</html>
);
}
10 changes: 6 additions & 4 deletions apps/www/components/custom/ColloboratorGridWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { cache } from '@repo/cache';
import ContributorsGrid from './Colloborators';
import ContributorsGrid from './Collaborators';

export default async function ContributorsGridWrapper() {
let contributors = [];
let contributors: ContributorData[] = [];

try {
const BATCH_SIZE = 20;
const redisKey = 'contributors';
const rawData = await cache.lrange(redisKey, 0, -1);
contributors = rawData
const rawData = await cache.lrange(redisKey, 0, BATCH_SIZE - 1);
contributors = rawData.map(item => item as ContributorData);
} catch (error) {
console.error('Error fetching contributors from Redis:', error);
return <div>Unable to load contributors. Please try again later.</div>;
}

return <ContributorsGrid data={contributors} />;
Expand Down
3 changes: 2 additions & 1 deletion packages/crypt/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
tsconfig.tsbuildinfo

0 comments on commit 7f532e1

Please sign in to comment.