Skip to content

Commit

Permalink
quick fix #2 for supabase cost
Browse files Browse the repository at this point in the history
  • Loading branch information
mimecuvalo committed Sep 1, 2024
1 parent 56b4c92 commit 6a5c283
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion data/resolvers/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
QueryFetchSiteMapArgs,
} from 'data/graphql-generated';
import { isAdmin, isAuthor } from './authorization';
import { kv } from '@vercel/kv';

import { Context } from 'data/context';
import { User } from '@prisma/client';
Expand Down Expand Up @@ -210,6 +211,12 @@ const Content = {
{ username, section, album, name }: QueryFetchCollectionArgs,
{ currentUsername, prisma }: Context
) {
if (!currentUsername) {
const data = await kv.hgetall(`${username}:${section}:${album}:${name}`);
if (data) {
return data.decoratedCollection;
}
}
const isOwnerViewing = currentUsername === username;

const sectionContent = await prisma.content.findFirst({
Expand Down Expand Up @@ -296,7 +303,11 @@ const Content = {
});
}

return decorateArrayWithPrefetchImages(decorateArrayWithRefreshFlag(collection));
const decoratedCollection = decorateArrayWithPrefetchImages(decorateArrayWithRefreshFlag(collection));
if (!currentUsername) {
await kv.hset(`${username}:${section}:${album}:${name}`, { decoratedCollection });
}
return decoratedCollection;
},

async fetchCollectionPaginated(
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@prisma/client": "5.5.2",
"@sentry/nextjs": "7.77.0",
"@vercel/analytics": "1.1.1",
"@vercel/kv": "2.0.0",
"apollo-server-micro": "3.10.3",
"aws-sdk": "2.1487.0",
"babel-plugin-formatjs": "10.5.7",
Expand Down Expand Up @@ -186,5 +187,6 @@
"post-merge": "./bin/post-merge"
}
},
"sideEffects": false
"sideEffects": false,
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
}
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5798,13 +5798,27 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@upstash/redis@^1.31.3":
version "1.34.0"
resolved "https://registry.yarnpkg.com/@upstash/redis/-/redis-1.34.0.tgz#f32cd53ebeeafbba7eca10f8597a573d5a2fed0d"
integrity sha512-TrXNoJLkysIl8SBc4u9bNnyoFYoILpCcFJcLyWCccb/QSUmaVKdvY0m5diZqc3btExsapcMbaw/s/wh9Sf1pJw==
dependencies:
crypto-js "^4.2.0"

"@vercel/[email protected]":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-1.1.1.tgz#2a712378a95014a548b4f9d2ae1ea0721433908d"
integrity sha512-+NqgNmSabg3IFfxYhrWCfB/H+RCUOCR5ExRudNG2+pcRehq628DJB5e1u1xqwpLtn4pAYii4D98w7kofORAGQA==
dependencies:
server-only "^0.0.1"

"@vercel/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@vercel/kv/-/kv-2.0.0.tgz#a0baa12563946cb35cee23d638b68f0fbbf76172"
integrity sha512-zdVrhbzZBYo5d1Hfn4bKtqCeKf0FuzW8rSHauzQVMUgv1+1JOwof2mWcBuI+YMJy8s0G0oqAUfQ7HgUDzb8EbA==
dependencies:
"@upstash/redis" "^1.31.3"

"@webassemblyjs/[email protected]", "@webassemblyjs/ast@^1.11.5":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24"
Expand Down Expand Up @@ -8242,6 +8256,11 @@ crypto-browserify@^3.12.0:
randombytes "^2.0.0"
randomfill "^1.0.3"

crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==

crypto-random-string@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5"
Expand Down

0 comments on commit 6a5c283

Please sign in to comment.