org-ql icon indicating copy to clipboard operation
org-ql copied to clipboard

:auto-category doesn't reflect updates in org-ql-view

Open akirak opened this issue 5 years ago • 9 comments

I have the following entry in org-ql-views:

'("Maybe" "maybe.org" (level 1)
  :super-groups
  ((:auto-category)))

It groups top-level headings in maybe.org by categories.

When I update CATEGORY property of a heading in org-mode and refresh the view buffer using org-ql-view-refresh, the heading still remains in the previous category. This might be about cache expiration, but I haven't investigated the details. This is probably a bug.

akirak avatar Dec 15 '20 02:12 akirak

When a buffer is modified, cached results for that buffer are no longer used, and the query is run in it anew. I don't know how the buffer could be modified without invalidating that buffer's cached results. Can you reproduce it in a clean Emacs config?

Note as well that grouping is a feature provided by org-super-agenda, so if there is a bug, it could be in either package, I guess.

alphapapa avatar Dec 15 '20 08:12 alphapapa

It turns out that org-get-category returns the same value after the value is changed.

org-get-category is defined as follows, and it returns the correct result when force-refresh is set to t.

(org-get-category &optional POS FORCE-REFRESH)

akirak avatar Dec 15 '20 10:12 akirak

In conclusion, this is not a bug with org-ql. It would be possible to work around this issue in org-super-agenda.el (in the following code), but I think org.el should invalidate the category cache whenever category is updated by org-set-property. In terms of performance, cache invalidation should occur only once per buffer, and not on every heading.

(org-super-agenda--def-auto-group category "their org-category property"
  :key-form (org-super-agenda--when-with-marker-buffer (org-super-agenda--get-marker item)
              (org-get-category))
  :header-form (concat "Category: " key))

akirak avatar Dec 15 '20 10:12 akirak

Yeah, that seems like an oversight in Org.

alphapapa avatar Dec 15 '20 22:12 alphapapa

Thanks, I'll consider if I can contribute to Org.

akirak avatar Dec 16 '20 02:12 akirak

I looked into this issue again. I am sorry, but you will have to work on it.

org-agenda.el doesn't suffer from this issue, and grouping with :auto-category works in (non-ql) agenda buffers even when categories are changed. It turns out that org-refresh-category-properties is called inside org-agenda-prepare-buffers function.

Org Ql already has its own cache system which properly detects modification. Thus you would probably have to call org-refresh-category-properties to refresh the category cache inside/before org-ql--select, which would degrade performance to some extent.

Because performance is one of the selling points of this package, it would be better if category refreshing were done only when needed, but I don't know if it could be implemented in a simple way.

When there is no modification in the buffer, Org Ql will remain as fast as it is now.

akirak avatar Dec 16 '20 13:12 akirak

I guess this will require a minor bit of infrastructure to do per-buffer preparation before running certain queries. Thanks for looking into it.

alphapapa avatar Dec 16 '20 23:12 alphapapa

Deferring this to 0.7.

alphapapa avatar Jun 18 '21 08:06 alphapapa

Deferring again. With the org-element caching features now under active development in Org, the org-get-category function looks a bit different now. This issue should probably be retested and the potential solutions, if necessary, reevaluated.

alphapapa avatar Dec 16 '23 11:12 alphapapa