diff --git a/src/computersandblues/lodestone/app.cljs b/src/computersandblues/lodestone/app.cljs index cfda9aa..98b6a9d 100644 --- a/src/computersandblues/lodestone/app.cljs +++ b/src/computersandblues/lodestone/app.cljs @@ -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) diff --git a/src/computersandblues/lodestone/database.cljs b/src/computersandblues/lodestone/database.cljs index 9930386..05fcc60 100644 --- a/src/computersandblues/lodestone/database.cljs +++ b/src/computersandblues/lodestone/database.cljs @@ -114,7 +114,7 @@ ([db store-id key-range {:keys [direction index]}] (let [store (open-store db store-id "readonly") key-range (if (= key-range ::all) - (js/IDBKeyRange.lowerBound "") + (js/IDBKeyRange.lowerBound js/Number.NEGATIVE_INFINITY) key-range) direction ({:asc "next" :desc "prev"} direction direction)] (if index