fix: overall perf improvements
* fix: ignore private ips * fix: performance related fixes * fix: simply event buffer * fix: default to 1 events queue shard * add: cleanup scripts * fix: comments * fix comments * fix * fix: groupmq * wip * fix: sync cachable * remove cluster names and add it behind env flag (if someone want to scale) * fix * wip * better logger * remove reqid and user agent * fix lock * remove wait_for_async_insert
This commit is contained in:
committed by
GitHub
parent
38cc53890a
commit
da59622dce
@@ -1,6 +1,6 @@
|
||||
import { generateSalt } from '@openpanel/common/server';
|
||||
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
import { cacheableLru } from '@openpanel/redis';
|
||||
import { db } from '../prisma-client';
|
||||
|
||||
export async function getCurrentSalt() {
|
||||
@@ -17,36 +17,36 @@ export async function getCurrentSalt() {
|
||||
return salt.salt;
|
||||
}
|
||||
|
||||
export async function getSalts() {
|
||||
const cache = await getRedisCache().get('op:salt');
|
||||
if (cache) {
|
||||
return JSON.parse(cache);
|
||||
}
|
||||
export const getSalts = cacheableLru(
|
||||
'op:salt',
|
||||
async () => {
|
||||
const [curr, prev] = await db.salt.findMany({
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
take: 2,
|
||||
});
|
||||
|
||||
const [curr, prev] = await db.salt.findMany({
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
take: 2,
|
||||
});
|
||||
if (!curr) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
|
||||
if (!curr) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
if (!prev) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
|
||||
if (!prev) {
|
||||
throw new Error('No salt found');
|
||||
}
|
||||
const salts = {
|
||||
current: curr.salt,
|
||||
previous: prev.salt,
|
||||
};
|
||||
|
||||
const salts = {
|
||||
current: curr.salt,
|
||||
previous: prev.salt,
|
||||
};
|
||||
|
||||
await getRedisCache().set('op:salt', JSON.stringify(salts), 'EX', 60 * 10);
|
||||
|
||||
return salts;
|
||||
}
|
||||
return salts;
|
||||
},
|
||||
{
|
||||
maxSize: 2,
|
||||
ttl: 60 * 5,
|
||||
},
|
||||
);
|
||||
|
||||
export async function createInitialSalts() {
|
||||
const MAX_RETRIES = 5;
|
||||
|
||||
Reference in New Issue
Block a user