fix: prevent partial preformatted cache after interrupted update#884
Open
benthamite wants to merge 1 commit into
Open
fix: prevent partial preformatted cache after interrupted update#884benthamite wants to merge 1 commit into
benthamite wants to merge 1 commit into
Conversation
citar-cache--preformat-bibliography previously called (clrhash preformatted) on the bib's cached hash and then refilled it in place via maphash + puthash. If the refill was interrupted partway through — e.g., C-g during an idle-time update of a large bibliography — the preformatted hash was left with only a fraction of the entries. Because citar-cache--update-bibliography had already set `props' before calling this function, subsequent cache checks saw "no changes needed" and the partial preformatted cache persisted indefinitely, causing citar--format-candidates to error with "No preformatted candidate string: KEY" on any entry that didn't make it into the hash before the interruption. Fix by building the new preformatted hash in a fresh local hash table and replacing the bib slot via setf only after maphash completes. If the maphash is interrupted, the setf never runs and the existing (valid) preformatted hash is retained. This mirrors the atomicity pattern introduced in emacs-citar#882 for the entries slot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
citar-cache--preformat-bibliographypreviously updated the bib's preformatted hash in place viaclrhashfollowed bymaphash+puthash. If the refill is interrupted partway through — for example,C-gduring an idle-time update of a large bibliography — the preformatted hash is left with only a fraction of the entries. Becausecitar-cache--update-bibliographyhas already setpropsbefore calling the preformatter, subsequent cache-up-to-date checks see "no changes needed" and the partial preformatted cache persists indefinitely.citar--format-candidatesthen errors withon any entry that didn't make it into the hash before the interruption, breaking
citar-insert-citation,citar-select-refs, etc.I hit this against a ~15k-entry bibliography: after some earlier interruption, the bib's entries cache had 14,662 keys but the preformatted cache only had 7,986. The partial state then persisted across Emacs sessions until
citar-cache--preformat-bibliographywas called manually.Fix
Build the new preformatted hash in a fresh local hash table and replace the bib slot via
setfonly aftermaphashcompletes. If the maphash is interrupted, thesetfnever runs and the existing (valid) preformatted hash is retained.This mirrors the atomicity pattern introduced in #882 for the entries slot.
Test plan
preformattedis fully populated (14,662/14,662) and the previously missing key resolves.eqreturns nil against the old slot value), confirming the atomic swap.