fix Analyse
This commit is contained in:
@@ -26,6 +26,7 @@ function saveDB(data) {
|
||||
}
|
||||
|
||||
let db = loadDB();
|
||||
let dirty = false;
|
||||
|
||||
function nextId() {
|
||||
db._counter = (db._counter || 0) + 1;
|
||||
@@ -45,10 +46,20 @@ export function trackEvent(type, userId, metadata = {}) {
|
||||
...metadata,
|
||||
};
|
||||
db.events.push(event);
|
||||
saveDB(db);
|
||||
dirty = true;
|
||||
return event;
|
||||
}
|
||||
|
||||
function flushToDisk() {
|
||||
if (!dirty) return;
|
||||
dirty = false;
|
||||
saveDB(db);
|
||||
}
|
||||
|
||||
setInterval(flushToDisk, 5000);
|
||||
process.on('SIGTERM', () => { flushToDisk(); process.exit(0); });
|
||||
process.on('SIGINT', () => { flushToDisk(); process.exit(0); });
|
||||
|
||||
export function getEvents({ from, to, type, user_id, limit = 100 } = {}) {
|
||||
let results = [...db.events];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user