diff --git a/package-lock.json b/package-lock.json index 7f96d4b..14abb32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10626,6 +10626,11 @@ "which": "^2.0.1" } }, + "crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==" + }, "crypto-browserify": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", diff --git a/package.json b/package.json index a7a4b4f..d48f14c 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@material-ui/icons": "^4.9.1", "@reach/router": "^1.3.4", "@types/react-router-dom": "^5.1.6", + "crypto": "^1.0.1", "graphql": "^15.3.0", "react": "^16.14.0", "react-dom": "^16.14.0", diff --git a/server/src/background-process.ts b/server/src/background-process.ts index 6a88148..90e7612 100644 --- a/server/src/background-process.ts +++ b/server/src/background-process.ts @@ -1,3 +1,4 @@ +import { createHash } from 'crypto' import { getRepository } from 'typeorm' import { Party } from './entities/Party' @@ -9,3 +10,9 @@ export async function deleteOldParties() { .where('TIMESTAMPDIFF(HOUR, latestTime, CURRENT_TIMESTAMP()) > 24') .execute() } + +// An expensive hash function to see how it affects performance. Copied from class slides. +export function expensiveFunction() { + const data = 'hash-me' + createHash('sha256').update(data).digest('base64') +} diff --git a/server/src/config.ts b/server/src/config.ts index 27c9f0c..8f17d1f 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -25,5 +25,5 @@ export const Config = { backgroundService: isServiceEnabled(AppService.BACKGROUND) ? true : !isProd(), wsUrl: process.env.WS_URL || 'ws://localhost:3000/graphqlsubscription', adminPassword: process.env.ADMIN_PASSWORD || 'password', - backgroundProcessInterval: 86400000, // In milliseconds. + backgroundProcessInterval: 100, // In milliseconds. } diff --git a/server/src/server.ts b/server/src/server.ts index 5b4d2b4..b18caaa 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -16,7 +16,7 @@ import { forAwaitEach, isAsyncIterable } from 'iterall' import path from 'path' import 'reflect-metadata' import { checkEqual, Unpromise } from '../../common/src/util' -import { deleteOldParties } from './background-process' +import { expensiveFunction } from './background-process' import { Config } from './config' import { migrate } from './db/migrate' import { initORM } from './db/sql' @@ -189,7 +189,6 @@ initORM() .catch(err => console.error(err)) setInterval(() => { - deleteOldParties() - .then(() => console.log('Background process run succesfully.')) - .catch(err => console.error(err)) + expensiveFunction() + console.log('Background process run succesfully.') }, Config.backgroundProcessInterval)