|
|
|
|
|
by codemonkey-zeta
317 days ago
|
|
Maybe I don't understand, but I thought the whole point of datomic (and XTDB by extension) was to avoid denormalization. I am surprised the author says: > "Old Yakread" has a lot of slow queries. For example, loading the subscriptions page on my account takes more than 10 seconds: for each of my hundreds of subscriptions, it has to run a query to figure out how many unread posts there are and when the most recent post was published. I would have thought you would grab all this data in a single query roughly like this: ;; Assuming XTDB v1.19+ or v2
(def q
'{:find [?sub-id ?unread-count ?last-pub]
:in [user-id]
:where [[?sub :subscription/user user-id]
[?sub :subscription/feed feed-id]
;; join to posts in that feed
[?post :post/feed feed-id]
[?post :post/published timestamp]
(not [?post :post/read-by user-id])
]
:find [(count ?post) ?unread-count
(max timestamp) ?last-pub]
:order-by [[?last-pub :desc]]})
^ AI disclaimer, but I think it gets the gist, you do your logical joins right in the query |
|