#Issue with liveInFiniteQueries?

1 messages · Page 1 of 1 (latest)

restive obsidian
#

Hey Everyone - would love some input. I am trying to implement liveInfiniteQueries and have created the following live query as an example:

  return useLiveInfiniteQuery(
    (q) => {
      if (label) {
        return q
          .from({ notes: notesCollection })
          .where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
          .where(({ notes }) => inArray(label, notes.labels))
          .orderBy(({ notes }) => notes.updated, "desc");
      } else {
        return q
          .from({ notes: notesCollection })
          .where(({ notes }) => and(eq(notes.archived, false), eq(notes.deleted, false)))
          .orderBy(({ notes }) => notes.updated, "desc");
      }
    },
    {
      pageSize: MAX_PAGE_SIZE,
      getNextPageParam: (lastPage, allPages) =>
        lastPage.length === MAX_PAGE_SIZE ? allPages.length : undefined,
    },
    [label]
  );
};```

Everything seems to work fine to start - I am able to jump between having labels, no labels, etc. However if I start updating any of the content the data stops updating and if I try to do an insert it flat out hangs the page - no error,  eventually get a page unresponsive, you can't even close the active tab, and a message about code being hung. Everything works perfectly with just a regular live query. Any one else experience this? Am I missing something? I realize it's still in beta but I havent seen any issues logged that seem related to this.
wise kestrel
#

hmm did you add logging to see where the infinite loop is happening?

#

what type are the collections? What is their syncMode?

restive obsidian
#

Hey - This is the collection - default sync… it seems to bail after note collection.insert (as well as update) is called but before it actually gets to onInsert as the API call never goes out the door - if there’s logging I could be doing inside DB I’m happy to do so if pointed in the right direction…

’’’export const notesCollection = createCollection(
queryCollectionOptions({
id: NOTES,
queryKey: [NOTES],
queryFn: async () => {
const res = await axiosInstance.get(/notes/);
return res.data as Note[];
},
queryClient,
schema: NoteSchema,
getKey: (item) => item._id,
onInsert: async ({ transaction }) => {
const { modified: note } = transaction.mutations[0];
await axiosInstance.post("/notes", note);
},
onUpdate: async ({ transaction }) => {
const { modified: note } = transaction.mutations[0];
await axiosInstance.patch(/notes/${note._id}, note);
},
onDelete: async ({ transaction }) => {
const ids = transaction.mutations.map(({ original }) => original._id);
await axiosInstance.post(/notes/bulkDelete, { ids });
},
})
);’’’

Edit - mobile hates me, sorry