Thank you for sharing it. The problem with this approach is that (a) you can’t plug it into existing pile of notes and (b) messing up with your customize file leads to broken agenda.
This post motivated me to share how I approach this problem that I am using for a month already and super happy about it’s performance. You can read detailed description on my blog. The code is available as a GitHub Gist.
TL;DR - in the before-save-hook
current buffer is traversed for existence of any TODO entires and Project
tag is either added or removed from #+ROAM_TAGS
property. Now, org-agenda
is adviced before to set the value of org-agenda-files
to the list of files with Project
tag (quieried from db, which is enourmously fast).
There is also a snipped to use for migration. This way all required information is always there, in your files and can be easily reconstructed. That being said, proposed solution can be easily adapted to dynamic-agenda-files
approach.
Hope someone finds it useful