Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FC-1437: fix/query limit #207

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/fluree/db/query/fql_resp.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@
"We only need to do this if there is an orderBy, otherwise limit and offset
were performed in index-range."
[sortPred sortOrder offset limit res]

(if (vector? res)
(cond->> res
sortPred (sort-by #(get % sortPred) compare-fn)
(= "DESC" sortOrder) (reverse)
offset (drop offset)
limit (take limit)) res))
sortPred (sort-by #(get % sortPred) compare-fn)
(= "DESC" sortOrder) reverse
offset (drop offset)
limit (take limit))
res))


(defn flakes->res
Expand Down Expand Up @@ -413,4 +413,4 @@
(get acc)
(sort-offset-and-limit-res sort-pred sort-order 0 limit)
(assoc acc select-pred)))
result sort-preds)))))
result sort-preds)))))
8 changes: 5 additions & 3 deletions src/fluree/db/query/subject_crawl/common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@
- :order - :asc or :desc
- :predicate - if type = :predicate, contains predicate pid or name
- :variable - if type = :variable, contains variable name (not supported for simple subject crawl)"
[results {:keys [type order predicate]} limit]
[results {:keys [type order predicate]} limit offset]
(if (= :variable type)
(throw (ex-info "Ordering by a variable not supported in this type of query."
{:status 400 :error :db/invalid-query}))
(let [sorted (cond-> (sort-by (fn [result] (get result predicate)) results)
(= :desc order) reverse)]
(vec (take limit sorted)))))
(into []
(comp (drop offset)
(take limit))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy these transducer comps always look backwards to me. But because it looks backwards, it must be right! ;)

sorted))))

(defn resolve-ident-vars
"When some variables may be idents (two-tuples) they need to get resolved into
Expand All @@ -154,4 +157,3 @@
"Provided: " v)
{:status 400 :error :db/invalid-query}))))
vars*))))

8 changes: 4 additions & 4 deletions src/fluree/db/query/subject_crawl/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
- order-by exists, in which case we need to perform a sort
- selectOne? exists, in which case we take the (first result)
- pretty-print is true, in which case each result needs to get embedded in a map"
[{:keys [selectOne? order-by pretty-print limit] :as parsed-query}]
[{:keys [selectOne? order-by pretty-print limit offset] :as parsed-query}]
(let [fns (cond-> []
selectOne? (conj (fn [result] (first result)))
pretty-print (conj (let [select-var (-> parsed-query
Expand All @@ -52,7 +52,8 @@
(subs 1))]
(fn [result]
(mapv #(array-map select-var %) result))))
order-by (conj (fn [result] (order-results result order-by limit))))]
order-by (conj (fn [result]
(order-results result order-by limit offset))))]
(if (empty? fns)
identity
(apply comp fns))))
Expand Down Expand Up @@ -87,7 +88,7 @@
:ident-vars ident-vars
:filter-map filter-map
:limit (if order-by util/max-long limit) ;; if ordering, limit performed by finish-fn after sort
:offset offset
:offset (if order-by 0 offset)
:permissioned? (not (get-in db [:permissions :root?]))
:parallelism 3
:f-where f-where
Expand All @@ -100,4 +101,3 @@
(if rdf-type?
(rdf-type-crawl opts)
(subj-crawl opts)))))