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.
|
"Returns a promise which resolves to the smallest or largest internal post id.
|
||||||
This is useful to continue interrupted paginated requests."
|
This is useful to continue interrupted paginated requests."
|
||||||
[max-or-min]
|
[max-or-min]
|
||||||
; this may look like a horribly inefficient way to get these numbers, and it is!
|
(->> (db/open-cursor! ::db/posts ::db/all {:index ::db/post-internal-id
|
||||||
; there was an earlier version that simply used an index on :internal_id and
|
:direction (if (= max-or-min :min) :asc :desc)})
|
||||||
; retrieved the first result in ascending or descending order; however, the
|
(db/first-result (keep (j/get :internal_id)))))
|
||||||
; 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))))))
|
|
||||||
|
|
||||||
(defn fetch-more-posts! [e]
|
(defn fetch-more-posts! [e]
|
||||||
(.preventDefault e)
|
(.preventDefault e)
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@
|
||||||
([db store-id key-range {:keys [direction index]}]
|
([db store-id key-range {:keys [direction index]}]
|
||||||
(let [store (open-store db store-id "readonly")
|
(let [store (open-store db store-id "readonly")
|
||||||
key-range (if (= key-range ::all)
|
key-range (if (= key-range ::all)
|
||||||
(js/IDBKeyRange.lowerBound "")
|
(js/IDBKeyRange.lowerBound js/Number.NEGATIVE_INFINITY)
|
||||||
key-range)
|
key-range)
|
||||||
direction ({:asc "next" :desc "prev"} direction direction)]
|
direction ({:asc "next" :desc "prev"} direction direction)]
|
||||||
(if index
|
(if index
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue