Change: (olp, olps) Optimize multiple args with heading query

This commit is contained in:
Adam Porter 2020-12-03 12:27:32 -06:00
parent 73209cf48e
commit 2d07cb0822
3 changed files with 49 additions and 29 deletions

View file

@ -521,6 +521,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
*Changed* *Changed*
+ Helm support (including the command =helm-org-ql=) has been moved to a separate package, =helm-org-ql=. + Helm support (including the command =helm-org-ql=) has been moved to a separate package, =helm-org-ql=.
+ Predicates ~outline-path~ and ~outline-path-segment~, when called with multiple arguments, optimize to a query like ~(and (heading LAST-OLP-ARG) (olp OTHER-OLP-ARGS))~, which is much faster.
*Internal* *Internal*
+ Predicates are now defined more cleanly with a macro (=org-ql-defpred=) that consolidates functionality related to each predicate. This will also allow users to more easily define custom predicates. + Predicates are now defined more cleanly with a macro (=org-ql-defpred=) that consolidates functionality related to each predicate. This will also allow users to more easily define custom predicates.

View file

@ -1170,9 +1170,17 @@ the following queries:
(olp \"Food\" \"Fruits\") (olp \"Food\" \"Fruits\")
(olp \"Fruits\" \"Grapes\") (olp \"Fruits\" \"Grapes\")
(olp \"Food\" \"Grapes\")" (olp \"Food\" \"Grapes\")"
:normalizers ((`(,predicate-names . ,strings) ;; FIXME: Stop regexp quoting when the (heading) predicate is changed to take a non-regexp string.
;; Regexp quote headings. :normalizers ((`(,predicate-names ,string)
`(outline-path ,@(mapcar #'regexp-quote strings)))) ;; Equivalent to (heading string), which is much faster.
`(heading ,(regexp-quote string)))
(`(,predicate-names . ,strings)
;; Rewrite query to use (heading) with the last string
;; and (olp) for the rest, which is much faster.
(let ((last (car (last strings)))
(rest (butlast strings)))
`(and (heading ,(regexp-quote last))
(outline-path ,@(mapcar #'regexp-quote rest))))))
:body (let ((entry-olp (org-ql--value-at (point) #'org-ql--outline-path))) :body (let ((entry-olp (org-ql--value-at (point) #'org-ql--outline-path)))
(cl-loop for h in regexps (cl-loop for h in regexps
always (cl-member h entry-olp :test #'string-match)))) always (cl-member h entry-olp :test #'string-match))))
@ -1195,9 +1203,17 @@ contiguous segment of the outline path:
(olp \"Food\" \"Grape\")" (olp \"Food\" \"Grape\")"
;; MAYBE: Allow anchored matching. ;; MAYBE: Allow anchored matching.
:normalizers ((`(,(or 'outline-path-segment 'olps) . ,strings) ;; FIXME: Stop regexp quoting when the (heading) predicate is changed to take a non-regexp string.
;; Regexp quote headings. :normalizers ((`(,predicate-names ,string)
`(outline-path-segment ,@(mapcar #'regexp-quote strings)))) ;; Equivalent to (heading string), which is much faster.
`(heading ,(regexp-quote string)))
(`(,predicate-names . ,strings)
;; Rewrite query to use (heading) with the last string
;; and (olp) for the rest, which is much faster.
(let ((last (car (last strings)))
(rest (butlast strings)))
`(and (heading ,(regexp-quote last))
(outline-path-segment ,@(mapcar #'regexp-quote rest))))))
:body (org-ql--infix-p regexps (org-ql--value-at (point) #'org-ql--outline-path))) :body (org-ql--infix-p regexps (org-ql--value-at (point) #'org-ql--outline-path)))
(org-ql-defpred path (&rest regexps) (org-ql-defpred path (&rest regexps)

View file

@ -966,6 +966,9 @@ File: README.info, Node: 06-pre, Next: 05, Up: Changelog
*Changed* *Changed*
• Helm support (including the command helm-org-ql) has been moved to • Helm support (including the command helm-org-ql) has been moved to
a separate package, helm-org-ql. a separate package, helm-org-ql.
• Predicates outline-path and outline-path-segment, when called
with multiple arguments, optimize to a query like (and (heading
LAST-OLP-ARG) (olp OTHER-OLP-ARGS)), which is much faster.
*Internal* *Internal*
• Predicates are now defined more cleanly with a macro • Predicates are now defined more cleanly with a macro
@ -1488,29 +1491,29 @@ Node: Links33872
Node: Tips34559 Node: Tips34559
Node: Changelog34877 Node: Changelog34877
Node: 06-pre35573 Node: 06-pre35573
Node: 0536196 Node: 0536416
Node: 04937673 Node: 04937893
Node: 04837947 Node: 04838167
Node: 04738294 Node: 04738514
Node: 04638689 Node: 04638909
Node: 04539089 Node: 04539309
Node: 04439448 Node: 04439668
Node: 04339805 Node: 04340025
Node: 04240000 Node: 04240220
Node: 04140161 Node: 04140381
Node: 0440402 Node: 0440622
Node: 03244335 Node: 03244555
Node: 03144714 Node: 03144934
Node: 0344911 Node: 0345131
Node: 02347886 Node: 02348106
Node: 02248114 Node: 02248334
Node: 02148382 Node: 02148602
Node: 0248581 Node: 0248801
Node: 0152616 Node: 0152836
Node: Notes52717 Node: Notes52937
Node: Comparison with Org Agenda searches52879 Node: Comparison with Org Agenda searches53099
Node: org-sidebar53751 Node: org-sidebar53971
Node: License54030 Node: License54250
 
End Tag Table End Tag Table