jamwt
jamwt15mo ago

How reactivity works

Thanks for the feedback! So whenever a table is .query'd, we keep track of the read ranges -- what index was used and what range within that index
4 Replies
jamwt
jamwtOP15mo ago
So if a given query function read records from two different tables at two different indexes, we "track" the fact those records were used to produce the final return value of that function then, a mutation comes by that insert, patch/update, or delete some record(s) for each of those records, we run a kind of "intersection" to see if it is within a read range of any subscribed queries if so, all of those queries are invalidated and re-run to produce a potentially new result. and that new result is pushed over the web socket to the convex client library this is a somewhat simplified version of how it works we do have a blog post underway called "How Convex Works" that goes into great detail about all this
oscklm
oscklm15mo ago
That makes sense, very cool - i'm looking forward to read the blog post. It's very interesting to me. Thanks Jamie!
json
json13mo ago
if a query does something like a filter and then a sum over a table, then returns the first few records from the result, will the query be re-run when items are added to the db? how does it work for those cases
jamwt
jamwtOP13mo ago
it will re-run, yes. it will basically always re-run when it should the reason is when you add items to the database, they are inserted into the range in an index the query was based on. so the query knows the result might have changed, and so it is re-run

Did you find this page helpful?