Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

org-ql-select with custom predicate does not refresh cache between searches #484

Closed
claudiusmueller opened this issue Jan 13, 2025 · 0 comments

Comments

@claudiusmueller
Copy link

OS/platform

openSUSE Leap 15.6

Emacs version and provenance

Emacs 29.4 - installed through openSUSE repository

Emacs command

KRunner -> "emacs"

Org version and provenance

org version 9.6.15 - builtin to emacs

org-ql package version and provenance

20240222.200

Actions taken

Before meetings I like to pull in topics I need to discuss with meeting attendees. I capture topics with a "topic" tag and a TARGET property that describes who this topic needs to be discussed with. See below:

** TODO topic 1 for Susie                                            :topic:
:PROPERTIES:
:OWNER:
:TARGET: Susie
:CREATED: [2025-01-12 Sun]
:END:
** TODO topic 2 for Bob                                              :topic:
:PROPERTIES:
:OWNER:
:TARGET: Bob
:CREATED: [2025-01-12 Sun]
:END:
** TODO topic 1 for Bob                                              :topic:
:PROPERTIES:
:OWNER:
:TARGET: Bob
:CREATED: [2025-01-12 Sun]
:END:

I wrote a custom org-ql predicate to search for items where the TARGET property matches a name:

  (org-ql-defpred target (name)
    "Search for entries where the \"TARGET\" property matches the supplied name."
    :body (and (property "TARGET")
               (string-match name (org-entry-get (point) "TARGET"))))

I then use this predicate in a simple function (simplified for a reprex here):

  (defun my-dupl-test-example ()
    "Collect open topics for a list of people and insert as headers by person."
    (interactive)

    ;; list of example persons
    (dolist (name (list "Bob" "Susie"))
      (insert (format "* %s\n" name))

      ;; get topics for a person
      (let ((results (org-ql-select (org-agenda-files)
                       '(and (target name) (tags "topic") (not (done)))
                       :action '(let ((heading (org-get-heading t t t t))
                                      (position (line-number-at-pos)))
                                  (if heading
                                      (let ((file (buffer-file-name)))
                                        (format "%s" heading)))))))

        ;; insert topics as headers
        (dolist (headline results)
          (insert (format "** %s\n" headline))))))

Observed results

The function inserts Bob's topics for both names IF the topics are found in a separate org file and the org-ql-search scope is set to "org-agenda-files":

* Bob
** topic 2 for Bob
** topic 1 for Bob
* Susie
** topic 2 for Bob
** topic 1 for Bob

If the topics are found in the same org file where they are supposed to be inserted and the org-ql-search scope is set to "current-buffer" it works correctly:

* Bob
** topic 2 for Bob
** topic 1 for Bob
* Susie
** topic 1 for Susie

I am completely guessing here that the items for Bob were returned both times because of a caching issue between searches. That does not explain why it works when the search is within current buffer though. I'm really at a loss of what to do about it or anything else I could test to find the source of the problem.

Expected results

The result should be:

* Bob
** topic 2 for Bob
** topic 1 for Bob
* Susie
** topic 1 for Susie

Backtrace

No response

Etc.

No response

Repository owner locked and limited conversation to collaborators Jan 14, 2025
@alphapapa alphapapa converted this issue into discussion #485 Jan 14, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant