Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitAuto: A performance of a page (/settings/integrations/jira) is too slow. #141

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions app/api/github/get-installed-repos/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { NextResponse } from "next/server";
import { Octokit } from "@octokit/rest";
import { createAppAuth } from "@octokit/auth-app";
import { getSession } from 'next-auth/react';
import { fetchInstalledRepos } from '@/lib/github';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req });
if (!session) return res.status(401).json({ error: 'Unauthorized' });

const repos = await fetchInstalledRepos(session.user.userId);
res.status(200).json(repos);

export interface GitHubOwnerWithRepos {
ownerId: number;
Expand Down
17 changes: 17 additions & 0 deletions app/lib/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { prisma } from '@/lib/prisma';
import NodeCache from 'node-cache';

const cache = new NodeCache({ stdTTL: 600 }); // Cache for 10 minutes

export async function fetchInstalledRepos(userId: string) {
const cacheKey = `installedRepos-${userId}`;
const cachedRepos = cache.get(cacheKey);
if (cachedRepos) return cachedRepos;

const repos = await prisma.repository.findMany({
where: { userId },
select: { id: true, name: true, url: true }, // Select only necessary fields
take: 50, // Limit to 50 repos per request
});
cache.set(cacheKey, repos);
return repos;
Loading