diff --git a/data/resolvers/content.ts b/data/resolvers/content.ts index 7807ca1..5964be4 100644 --- a/data/resolvers/content.ts +++ b/data/resolvers/content.ts @@ -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'; @@ -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({ @@ -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( diff --git a/package.json b/package.json index 0e0bd3c..63db616 100644 --- a/package.json +++ b/package.json @@ -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", @@ -186,5 +187,6 @@ "post-merge": "./bin/post-merge" } }, - "sideEffects": false + "sideEffects": false, + "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" } diff --git a/yarn.lock b/yarn.lock index d2cf06b..b7bd4f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5798,6 +5798,13 @@ 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/analytics@1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-1.1.1.tgz#2a712378a95014a548b4f9d2ae1ea0721433908d" @@ -5805,6 +5812,13 @@ dependencies: server-only "^0.0.1" +"@vercel/kv@2.0.0": + 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/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": version "1.11.6" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" @@ -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"