Not all links to a node come from another node. Persisting OLP data
allows us to build backlinks with information about these non-node
headings.
Revert: db4170a459.
As it happens, turning sexps into strings is one of the
computationally expensive steps in EmacSQL.
With an enormous number of links in the database, that's a lot
of (:outline nil) to stringify into "(:outline nil)".
Its only use was in org-roam-node-insert-section,
where the information is very cheap to reconstruct.
It's already in one of the other arguments!
This has passed unnoticed because org-roam-db-sync has other
performance tarpits, but it will probably be noticed eventually after
those get fixed.
To avoid having to create a wrapper function and silence the byte-
compiler for both when using a pre-rename and post-rename Org, keep
it simple and just depend on Org 9.6.
That function was added two years ago and the first release that
provided it was v4.0.0. It automatically picks the best available
back-end, `emacsql-sqlite-builtin' or `emacsql-sqlite-module'.
In v4.0.0 it could also fall back to the legacy `emacsql-sqlite'.
The inferior third-party back-ends are no longer supported.
Emacsql v4.1.0, which will be releases in early December, removes
the legacy `emacsql-sqlite' back-end (which used a custom binary).
org mode timestamps do not support time zones, so returning the
machine's local time zone is misleading.
Also, org-format-time-string is an obsolete alias of format-time-string.
Ref: cc2490a706
One example of an edge case:
- If a file has LF line endings,
- and is situated in a repository where .editorconfig asks for
CRLF,
(Such repositories exist, for example
<https://github.com/obsidianmd/obsidian-docs/>.)
- and editorconfig-mode is enabled,
org-roam-db--file-hash would then return different results depending
on whether the file path is passed to it or not.
While this is a contrived edge case, there may be other cases like
this where the data from insert-file-contents-literally and the data
from find-file-noselect makes secure-hash return different values.
This commit removes the branch in org-roam-db--file-hash to compute
the hash based on buffer content, instead making it always require a
file path.
(This commit also allows org-roam-db-insert-file to take an optional
HASH argument, allowing it to avoid recalculating the hash.)
Since now we always compute the hash with the file on disk, the
special case for encrypted files is no longer needed.
This should have no impact on whether db is synchronized. The only
case when db--file-hash uses the "calculate in current buffer" path is
in db-insert-file; the only use of db-insert-file is in
db-update-file, which already calls db--file-hash with the file path,
and does not rely on the value from the current buffer.
When trying to save from a narrowed buffer, only the Roam nodes visible
in the narrowed buffer are written to the database.
This commit ensures that org-roam behaves the same whether the current
buffer is narrowed or not.
Previously we only updated the database on file save, but we need to
update the file's atime on file access, so we hook into `find-file-hook`
to do so. We only update the file atime if the file exists in the file table.
Adds two customizable variables: org-roam-db-extra-links-elements and
org-roam-db-extra-links-exclude-keys, which govern which elements are to
be considered for link parsing by Org-roam.
Also added sane defaults to org-roam-db-extra-links-exclude-keys.
* (fix):db: pragma foreign keys to work with sqlite3
This commit is follow-up for PR #2009 should fix issues #1927 & #1910.
Currently, `[:pragma (= foreign_keys ON)]` is present only in function
`org-roam-db--init`. This means the `foreign_keys` is turned on only when the db
file is created for the first time. Subsequent Emacs sessions won't turn it on
as the db file is already present and does not evaluate `org-roam-db--init`.
This PRAGMA needs to be turned on each database connection at runtime according
to sqlite's documentation (https://sqlite.org/foreignkeys.html#fk_enable)
```
Foreign key constraints are disabled by default (for backwards compatibility),
so must be enabled separately for each database connection
```
I have observed that on Windows only the Emacs session that initially creates
the Org-roam db file works correctly with the `sqlite3` option. Subsequent Emacs
sessions have the same "Unique constraint failed" error messages.
I have tested this patch on Windows and Ubuntu; both seem to work in the first
and subsequent Emacs sessions.
I am not 100% sure if the location of the PRAGMA is the best; use it as a
proof-of-cocenpt for the fix. Thank you.
* remove: [:pragma (= foreign_keys ON)] from org-roam-db--init
* fix: defconst org-roam--sqlite-available-p outputs error
When `org-roam-database-connector` is not `sqlite`, it outputs an unnecessary
error when Org-roam starts up as `defconst` evaluates
`(emacsql-sqlite-ensure-binary)`.
```
Org-roam initialization: (error "No EmacSQL SQLite binary available, aborting")
```
For other database connectors, this is not relevant.
* chore: rm org-roam--sqlite-available-p
As per our conversation, org-roam--sqlite-available-p not needed.
Previously node caching used org-map-entries: this only mapped over agenda
entries, hence skipping various nodes. Instead, we should be using
org-map-region, which maps over the entire file.
Org-ref v3 introduced a new citation syntax, and removed some functions
that org-roam had previously relied upon (e.g. for extracting keys from
multi-citations).
This commit introduces support on two fronts:
1. Add `org-roam-org-ref-path-to-keys` which converts a link path to a
list of keys. This supports both Org-ref v2 and v3.
2. Adds support for parsing multi-citations in refs.