mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Use next-basics package.
This commit is contained in:
parent
1a6af8fc41
commit
f4e0da481e
62 changed files with 255 additions and 373 deletions
19
lib/redis.js
19
lib/redis.js
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue