Skip to content

Commit

Permalink
feat: save queries for analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
sznowicki committed Dec 22, 2023
1 parent d93cde4 commit cd158b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export const onRequestGet = async (context) => {
const facets = await getFacets(env);
const langs = [...facets.lang.values()].sort((a,b) => a.count > b.count ? -1 : 1);

// Save used queries for analytics
if (q) {
await context.env.KUKEI_QUERIES.put(
q,
JSON.stringify({
hasResults,
}),
{
expirationTtl: 86400, // 24h
}
);
}
const view = {
...viewDefaults,
q,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Szymon Nowicki <[email protected]>",
"license": "UNLICENSED",
"scripts": {
"dev": "wrangler pages dev dist --compatibility-flag=nodejs_compat --compatibility-date=2023-12-05",
"dev": "wrangler pages dev dist --kv=KUKEI_QUERIES --compatibility-flag=nodejs_compat --compatibility-date=2023-12-05",
"test": "node --test",
"make:hash": "node ./scripts/make-hash.js",
"build": "yarn make:hash && yarn install --production",
Expand Down

0 comments on commit cd158b9

Please sign in to comment.