From 8a7d4578ea6e11f22d7fb8f1e246bf8438751953 Mon Sep 17 00:00:00 2001 From: Szymon Nowicki Date: Fri, 22 Dec 2023 19:49:32 +0100 Subject: [PATCH] feat: remove mongo analytics (too slow), make CF KV not expire --- functions/index.js | 6 +----- lib/mongo.js | 24 ------------------------ 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/functions/index.js b/functions/index.js index dad0f2e..cacc61e 100644 --- a/functions/index.js +++ b/functions/index.js @@ -66,12 +66,8 @@ export const onRequestGet = async (context) => { q, JSON.stringify({ hasResults, - }), - { - expirationTtl: 86400, // 24h - } + }) ); - await trackQuery(context.env, { q, hasResults }); } const view = { ...viewDefaults, diff --git a/lib/mongo.js b/lib/mongo.js index b2e6570..629c86e 100644 --- a/lib/mongo.js +++ b/lib/mongo.js @@ -50,27 +50,3 @@ export const getUnchecked = async (envs) => { return response?.documents?.[0]?.count ?? null; }; - -export const trackQuery = async (envs, {q, hasResults}) => { - const d = Date.now(); - await callMongo(envs, 'updateOne', { - collection: 'queries', - database: envs.ATLAS_DB, - dataSource: envs.ATLAS_SOURCE, - filter: { - q, - }, - update: { - $inc: { - used: 1, - }, - $set: { - q, - hasResults, - lastUse: Date.now() - } - }, - upsert: true, - }); - console.log(`Analytics via mongo took ${Date.now() - d}ms`); -};