Use next-basics package.

This commit is contained in:
Mike Cao 2022-08-28 20:20:54 -07:00
parent 1a6af8fc41
commit f4e0da481e
62 changed files with 255 additions and 373 deletions

View file

@ -1,10 +1,11 @@
import { createClient } from 'redis';
import { startOfMonth } from 'date-fns';
import { getSessions, getAllWebsites } from '/queries';
import debug from 'debug';
import { getSessions, getAllWebsites } from 'queries';
import { REDIS } from 'lib/db';
const log = debug('db:redis');
const REDIS = Symbol.for('redis');
const log = debug('umami:redis');
const INITIALIZED = 'redis:initialized';
async function getClient() {
const redis = new createClient({
@ -38,7 +39,7 @@ async function stageData() {
await addRedis(sessionUuids);
await addRedis(websiteIds);
await redis.set('initialized', 'initialized');
await redis.set(INITIALIZED, 1);
}
async function addRedis(ids) {
@ -52,12 +53,12 @@ async function addRedis(ids) {
let redis = null;
(async () => {
redis = global[REDIS] || (await getClient());
redis = process.env.REDIS_URL && (global[REDIS] || (await getClient()));
const value = await redis.get('initialized');
if (!value) {
await stageData();
if (redis) {
if (!(await redis.get(INITIALIZED))) {
await stageData();
}
}
})();