whats wrong with my index??
When I apply the index below, I get the following error:
My query
Here's my schema for reference
12 Replies
I think it has to do with the gte, but not sure how that is causing the cursor issue. To note, the postdated is being stored as isostring
Ah shoot, OK I think I read the api incorrectly. Will check once I get a chance
nevermind, the api is correct...filter and withIndex api is different...bah, please help
Also to note, I'm storing my custom dates as ISO strings on a string field.
yea i think its due to timestamp format not being numerical. need to test still
nope, still doesnt work...
Where does
filter
come from? This error usually indicates running a paginated query over one index, and then running it again (by calling loadMore or reacting to the data changing) with a different indexHey!
Filter, and all other dynamic variables are defined from the beginning.
I think it may have to do with me calculating a timestamp at runtime, even though its not asynchronous, im wondering if convex does something to immediately run the query so that once my calculation is done, it re sets?
my calculateTimestamp looks like
Thats weird, when i try to use calculateTimestamp in the frontend, before passing it to convex function, i get an infinite loop...
memoizing seems to have done the trick. although, this feels a bit hacky
it looks like every time
getThreads
runs, it picks a different timeFrameStart
. in order to paginate over a consistent range of the data, the query needs to use the same index filters. the query is running multiple times, once for each page of the pagination, and each time it should have the same q.gte
filters or it will reset
memoization sounds like a good solution. with calculateTimestamp
returning a different value each time, you will either get these errors from convex or an infinite loop in react or something like that.thank you for that...makes sense now. wdyt about the memoizedTimestamp workaround
my goal is to select timeframes that are say a month old from today or a year old from today.
may i ask what your approach would be, if not memoizing the timestamp?
you could also change
calculateTimestamp
to zero out the hour/minute/second so it effectively rounds to the nearest day, which would return a consistent value unless you're on a day boundary (in which case it would throw error + reoload once which should be fine)hmm
if you do that on the client side, convex may be able to cache more. but i'm not sure whether it's better than memoizing
okay, i think i understand..let me make an attempt..
you could also memoize
new Date()
on the client and pass it in as an argument. anything that doesn't cause a different index range each time should work.by zeroing out do you mean
now.setHours(0, 0, 0, 0);
?
and hmm, okay okay, thank you. goodness glad to be over this hump
at least, be able to see the horizon
made a hook for this
Also, i have another question/issue related to pagination, should i create another post or can i ask here?Making another post is helpful for making the question/answer discoverable for the community.