Fork me on GitHub
#datomic
<
2022-03-27
>
steveb8n21:03:35

Q: I want to query “last-updated” date-time for n entities. it’s not obvious how to do this because a change to any attribute in the entity is an “update”. has anyone found a way to do this?

kenny22:03:43

Explicitly model it. Don't use Datomic’s history for this.

steveb8n06:03:51

I have done that for parent entities when children are updated. why model this instant value when it is in history?

kenny13:03:40

Because you have control over it.

steveb8n22:03:56

fair enough. having thought about it a bit, I’m going to follow your advice. thx for the nudge

Ivar Refsdal11:03:46

PS. Don't forget that two (Date.) may be equal, i.e. refer to the same millisecond. Thus if you are asserting: :e/updated (Date.) twice fast enough on the same entity, you may loose data. If you are not loosing data now, you may in the future as latency decreases. I'm not sure it's a very good idea to explicitly model this. To me it seems this should be something that Datomic "can do". I have solved this (for certain types of data) in https://github.com/ivarref/rewriting-history. You can have a look at the function pull-flat-history. This allows you to get the (relative) latest update of some entity.

Ivar Refsdal11:03:35

Warning. I'm pretty sure pull-flat-history is slow.