Skip to content

Commit

Permalink
feat: remove mongo analytics (too slow), make CF KV not expire
Browse files Browse the repository at this point in the history
  • Loading branch information
sznowicki committed Dec 22, 2023
1 parent a485b07 commit 8a7d457
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
6 changes: 1 addition & 5 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 0 additions & 24 deletions lib/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
};

0 comments on commit 8a7d457

Please sign in to comment.