Fix index lookup for minimal and maximal favorite id
This commit is contained in:
parent
7ea11bfeb4
commit
7d359c2ed7
2 changed files with 4 additions and 15 deletions
|
|
@ -417,20 +417,9 @@
|
|||
"Returns a promise which resolves to the smallest or largest internal post id.
|
||||
This is useful to continue interrupted paginated requests."
|
||||
[max-or-min]
|
||||
; this may look like a horribly inefficient way to get these numbers, and it is!
|
||||
; there was an earlier version that simply used an index on :internal_id and
|
||||
; retrieved the first result in ascending or descending order; however, the
|
||||
; result that was returned was unexpected and unreliable. this may very well
|
||||
; have been my fault, because i'm only learning how the indexeddb api works as
|
||||
; i implement all of this here.
|
||||
(let [xform (comp (keep (j/get :internal_id)))
|
||||
rf (if (= max-or-min :min) min max)
|
||||
init (if (= max-or-min :min) js/Number.POSITIVE_INFINITY js/Number.NEGATIVE_INFINITY)]
|
||||
(. (->> (db/open-cursor! ::db/posts ::db/all)
|
||||
(db/transduce-cursor xform rf init))
|
||||
(then (fn [result]
|
||||
(when-not (infinite? result)
|
||||
result))))))
|
||||
(->> (db/open-cursor! ::db/posts ::db/all {:index ::db/post-internal-id
|
||||
:direction (if (= max-or-min :min) :asc :desc)})
|
||||
(db/first-result (keep (j/get :internal_id)))))
|
||||
|
||||
(defn fetch-more-posts! [e]
|
||||
(.preventDefault e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue