Fork me on GitHub
#biff
<
2023-02-13
>
Epidiah Ravachol20:02:35

I have a situation where I'm using biff/submit-tx to update a user and then biff/lookup to get that user's new data and pop it back into the UI. The problem is, the lookup is returning the information from immediately before the submit-tx. It doesn't seem to want to wait for the new info. I tried putting a xtdb/sync between them, but that didn't seem to have an effect. Even a good long Thread/sleep doesn't change the situation, but refreshing the page immediately following the completing the form gives me the up-to-date info.

pavlosmelissinos20:02:46

Ooh, I know this one! biff/lookup takes a db as input, which is immutable, so if you use the db of the request after a transaction it won't be updated in-place. What you want is (biff.xtdb/db biff.xtdb/node)

1
🙌 1
Epidiah Ravachol20:02:37

Yes! That did the trick!

🙂 1
pavlosmelissinos20:02:03

I think, because it's a db, we expect it to always "point" at the latest version but xtdb is bitemporal so it doesn't have to be like that. Its db is actually a snapshot of your state at a certain point in time.

pavlosmelissinos20:02:23

and node is an overarching thing that contains all the snapshots

pavlosmelissinos20:02:39

That's how I understand it anyway 🙂

Epidiah Ravachol20:02:54

That makes sense. Especially now that I think back to doing those XTDB tutorials and having to call xt/db on node all the time. merge-context was definitely under my radar. Might have to look at the Biff API with fresh eyes again!

pavlosmelissinos20:02:28

It takes some getting used to but once you grok it I think it's a much simpler model to reason about than relational DBs (where you don't even have any insights about the past).

1
Epidiah Ravachol20:02:20

I'm looking forward to wielding the power of time travel...responsibly.

😄 1