Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Feb 2, 2024
1 parent acf7349 commit 48eba0f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"wipedist": "rimraf \"dist/\"",
"start": "yarn build && concurrently \"tsc -w -p src\" \"node dist/\"",
"test": "concurrently \"tsc -p src\" \"yarn test:lint\" \"yarn test:unit\"",
"test:lint": "eslint *.ts \"{src,tests}/**/*.ts\"",
"test:lint": "eslint --quiet *.ts \"{src,tests}/**/*.ts\"",
"test:unit": "vitest run --coverage --config vitest.unit.config.ts",
"dev": "yarn wipedist && tsc -w -p src",
"test:watch": "vitest --config vitest.unit.config.ts --coverage",
Expand Down
20 changes: 11 additions & 9 deletions src/lib/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,18 @@ export async function processPendingActivities() {
}
});

await prisma.activity.updateMany({
where: {
id: {
in: activities.map(i => i.id)
if (activities.length > 0) {
await prisma.activity.updateMany({
where: {
id: {
in: activities.map(i => i.id)
}
},
data: {
completed: true
}
},
data: {
completed: true
}
});
});
}

await Promise.all(activities.map(completeActivity));
return activities;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/settings/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Activity, activity_type_enum, Prisma, PrismaClient } from '@prisma/clie

import { production } from '../../config';
import { ActivityTaskData } from '../types/minions';
import { sqlLog } from '../util/logger';

declare global {
namespace NodeJS {
Expand All @@ -29,15 +30,14 @@ function makePrismaClient(): PrismaClient {
export const prisma = global.prisma || makePrismaClient();
global.prisma = prisma;

export const prismaQueries: Prisma.QueryEvent[] = [];
export let queryCountStore = { value: 0 };

if (isMainThread) {
// @ts-ignore ignore
prisma.$on('query' as any, (_query: any) => {
if (!production && globalClient.isReady()) {
const query = _query as Prisma.QueryEvent;
prismaQueries.push(query);
const query = _query as Prisma.QueryEvent;
if (!production) {
sqlLog(query.query);
}
queryCountStore.value++;
});
Expand Down
9 changes: 9 additions & 0 deletions src/lib/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const sonicBoom = new SonicBoom({
sync: false
});

const sqlLogger = new SonicBoom({
fd: './logs/queries.sql',
mkdir: true,
minLength: 0,
sync: true
});

export const sqlLog = (str: string) => sqlLogger.write(`${str}\n`);

interface LogContext {
type?: string;
[key: string]: unknown;
Expand Down
4 changes: 1 addition & 3 deletions vitest.integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export default defineConfig({
include: ['src/lib/MUser.ts']
},
testTimeout: 30_000,
bail: 1,
minThreads: 3,
maxThreads: 3
bail: 1
}
});

0 comments on commit 48eba0f

Please sign in to comment.