Skip to content

Commit

Permalink
fix: speed up assigning many custom points at once
Browse files Browse the repository at this point in the history
do not sync those points with Intra right away, let the synchronization tool handle it
  • Loading branch information
FreekBes committed Dec 27, 2024
1 parent 18be659 commit a9e1a76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/handlers/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const INCLUDE_IN_SCORE_RETURN_DATA = {
},
};

export const createScore = async function(prisma: PrismaClient, type: CodamCoalitionFixedType | null, typeIntraId: number | null, userId: number, points: number, reason: string, scoreDate: Date = new Date()): Promise<CodamCoalitionScore | null> {
export const createScore = async function(prisma: PrismaClient, type: CodamCoalitionFixedType | null, typeIntraId: number | null, userId: number, points: number, reason: string, scoreDate: Date = new Date(), syncWithIntra: boolean = true): Promise<CodamCoalitionScore | null> {
// Retrieve user details
const user = await prisma.intraUser.findFirst({
where: {
Expand Down Expand Up @@ -64,8 +64,10 @@ export const createScore = async function(prisma: PrismaClient, type: CodamCoali
},
include: INCLUDE_IN_SCORE_RETURN_DATA,
});
const api = await getAPIClient();
score.intra_score_id = await syncIntraScore(prisma, api, score, true); // Sync the score with Intra
if (syncWithIntra) {
const api = await getAPIClient();
score.intra_score_id = await syncIntraScore(prisma, api, score, true); // Sync the score with Intra
}
return score;
}

Expand Down
4 changes: 2 additions & 2 deletions src/routes/admin/points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs';
import { fetchSingleApiPage, getAPIClient, getBlocAtDate, getOffset, getPageNav, getPageNumber } from '../../utils';
import { ExpressIntraUser } from '../../sync/oauth';
import { createScore, handleFixedPointScore, shiftScore } from '../../handlers/points';
import { deleteIntraScore, syncIntraScore, syncTotalCoalitionScore } from '../../handlers/intrascores';
import { deleteIntraScore, syncIntraScore, syncTotalCoalitionScore, syncTotalCoalitionsScores } from '../../handlers/intrascores';

const SCORES_PER_PAGE = 100;

Expand Down Expand Up @@ -642,7 +642,7 @@ export const setupAdminPointsRoutes = function(app: Express, prisma: PrismaClien
continue;
}
console.log(`User ${sessionUser.login} is assigning ${scoreToCreate.points} custom points manually to ${user.login} with reason "${scoreToCreate.reason}"`);
const score = await createScore(prisma, null, null, user.id, scoreToCreate.points, scoreToCreate.reason);
const score = await createScore(prisma, null, null, user.id, scoreToCreate.points, scoreToCreate.reason, new Date(), false);
if (!score) {
console.warn(`Failed to create score for user ${user.login}`);
failedScores.push({ login: user.login, amount: scoreToCreate.points, error: 'Failed to create score' });
Expand Down

0 comments on commit a9e1a76

Please sign in to comment.