datacore
datacore copied to clipboard
feat: Track file access time, new hook based on access time
This PR adds a new optional intrinsic field $atime?: DateTime to the File interface, and updates the MarkdownPage, Canvas, and GenericFile implementations to conform. $atime is also added to the JSON representations for the above 3 classes:
- https://github.com/blacksmithgu/datacore/commit/d1e1c091e6e6d92c5783a398deed00dca1377a9e
Some type narrowing utilities for the indexable interfaces were added during this work to assist with satisfying the type checker:
- https://github.com/blacksmithgu/datacore/commit/68a044cf553a6e1a35940dceaffde134f00b98c7
We track $atime using the Obsidian Workspace file-open event:
- https://github.com/blacksmithgu/datacore/commit/a7ada90c73cabb3bc5aec912d0a826c123b4f18d
We also add a new hook, useLastOpenedFiles, for getting a list of the most recently accessed files via this new metadata:
- https://github.com/blacksmithgu/datacore/commit/40f4f2c951177247695f8d84be653c42e82dcf78
I'm a bit worried about having this data actually be inside of Datacore's index - the index currently is only updated when the underlying file changes, whereas this now introduces updates on every file open potentially which can be much higher cadence.
Additionally, I believe if you mutate the file, the access time will be lost since the indexer and FileStats object do not have last access time.
As an interim, perhaps we can add the hook where recent file accesses are stored directly via a queue of recent file accesses? We can persist it to local storage as well to make it work across loads.
I actually have some more changes locally that address the mutation story, but I was starting to feel bad about inundating you with unsolicited PR's with non-trivial scope.
That said, it's not a very ergonomic change set, a different data structure might in fact be more appropriate like you're suggesting. So I'll probably evaluate a different approach instead of pushing those changes up.
Anecdotally, I haven't seen any issues with index updates triggering on file access, and I've built a few dashboards on top of this. But I do see where there could be potential for problems with updating the revision with every access. So I'll look at that while I'm revisiting this as well.