about summary refs log tree commit diff
path: root/src/state/queries
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-12-11 13:53:37 -0800
committerGitHub <noreply@github.com>2023-12-11 13:53:37 -0800
commit99cf6b626fd955b94bde04c2153cbe8bad53699d (patch)
tree670015b6d4ffac1823b2c85a72e9d4991e7c76fc /src/state/queries
parentab04074197f8432a3d502ca2393beca3b8f6ca97 (diff)
downloadvoidsky-99cf6b626fd955b94bde04c2153cbe8bad53699d.tar.zst
Additional reductions in request traffic (#2169)
* Dont poll for new content on profiles

* Drop the whenAppReady query after new post to reduce traffic overhead

* Reduce getPosts calls in notifs to only use them when needed
Diffstat (limited to 'src/state/queries')
-rw-r--r--src/state/queries/notifications/feed.ts1
-rw-r--r--src/state/queries/notifications/unread.tsx4
-rw-r--r--src/state/queries/notifications/util.ts16
3 files changed, 15 insertions, 6 deletions
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts
index b6aa3d753..1610fc0bf 100644
--- a/src/state/queries/notifications/feed.ts
+++ b/src/state/queries/notifications/feed.ts
@@ -76,6 +76,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
           queryClient,
           moderationOpts,
           threadMutes,
+          fetchAdditionalData: true,
         })
       }
 
diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx
index ba38463f2..a189f20e4 100644
--- a/src/state/queries/notifications/unread.tsx
+++ b/src/state/queries/notifications/unread.tsx
@@ -102,6 +102,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
             queryClient,
             moderationOpts,
             threadMutes,
+
+            // only fetch subjects when the page is going to be used
+            // in the notifications query, otherwise skip it
+            fetchAdditionalData: !!invalidate,
           })
           const unreadCount = countUnread(page)
           const unreadCountStr =
diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts
index 48e1b8dd8..9fb25867a 100644
--- a/src/state/queries/notifications/util.ts
+++ b/src/state/queries/notifications/util.ts
@@ -27,12 +27,14 @@ export async function fetchPage({
   queryClient,
   moderationOpts,
   threadMutes,
+  fetchAdditionalData,
 }: {
   cursor: string | undefined
   limit: number
   queryClient: QueryClient
   moderationOpts: ModerationOpts | undefined
   threadMutes: string[]
+  fetchAdditionalData: boolean
 }): Promise<FeedPage> {
   const res = await getAgent().listNotifications({
     limit,
@@ -49,12 +51,14 @@ export async function fetchPage({
 
   // we fetch subjects of notifications (usually posts) now instead of lazily
   // in the UI to avoid relayouts
-  const subjects = await fetchSubjects(notifsGrouped)
-  for (const notif of notifsGrouped) {
-    if (notif.subjectUri) {
-      notif.subject = subjects.get(notif.subjectUri)
-      if (notif.subject) {
-        precacheResolvedUri(queryClient, notif.subject.author) // precache the handle->did resolution
+  if (fetchAdditionalData) {
+    const subjects = await fetchSubjects(notifsGrouped)
+    for (const notif of notifsGrouped) {
+      if (notif.subjectUri) {
+        notif.subject = subjects.get(notif.subjectUri)
+        if (notif.subject) {
+          precacheResolvedUri(queryClient, notif.subject.author) // precache the handle->did resolution
+        }
       }
     }
   }