Open tyler-dot-earth opened 3 days ago
Remove debounce from refreshBookExport I suspect this only ever existed because the 'delete' listener fires for each file that is deleted, which in turn was firing the refreshBookExport function a ton of times. (it isn't called in the 'delete' listener anymore - keep reading)
I'd definitely like us to confirm this... @tadeoos do you recollect the original rationale?
@TristanH
Remove debounce from refreshBookExport I suspect this only ever existed because the 'delete' listener fires for each file that is deleted, which in turn was firing the refreshBookExport function a ton of times. (it isn't called in the 'delete' listener anymore - keep reading)
I'd definitely like us to confirm this... @tadeoos do you recollect the original rationale?
Please do! I could only guess based on the code and behavior.
Given the debounce was 800ms, I can't imagine it was to compensate for some backend behavior (eg a slow sync process that would get confused by "outdated" refreshBookExport
request)
The relevant changes call refreshBookExport
significantly less as it is simply no longer called immediately upon deletion of every single file, instead deferring to the normal sync schedule or manual re-sync.
So beyond spamming the request, which this PR significantly reduces, i suppose the question to answer is: is there any point in keeping the debounce?
That said, I can also say:
requestSync
was never similarly debounced (though perhaps that's a problem of its own)@TristanH alright, i tested the heck out of this today — behavior seems solid, and I think I fixed a few more related bugs along the way.
added a ton of notes to the original post, and a big list of steps for testing.
enjoy!
added an install for testing
section to OP with instructions on testing via BRAT instead of having to manually clone & install.
Noticing that null
is being added to books to refresh
.
Not necessarily a problem - this happened before, too - but will see if there's something specific causing it. Would be easy to filter them out, but would be better if it didn't happen to begin with.
sync changes
Primarily:
refreshBookExport
asyncdebounce
from refreshBookExportrefreshBookExport
function a ton of times. (it isn't called in the 'delete' listener anymore - keep reading)refreshBookExport
All of these combined should ensure a much more reliably sync operation.
Extensive testing instructions found at bottom of this post ⤵
notes dump
clean plugin install happens
default
data.json
(akasettings
):user clicks "connect"
getUserAuthToken()
→ saves tosettings.token
https://readwise.io/export/obsidian/preferences
note that sync frequency is manual/
0
at this pointuser initiates initial/first sync — this can happen one of several ways:
refreshBookExport
Sync your data now
commandrefreshBookExport
refreshBookExport
onload
→refreshBookExport
configureSchedule
→refreshBookExport
after the initial sync,
settings.lastSavedStatusID
andsettings.booksIDsMap
are populatedat this point, the user may also use the
Delete and reimport this document
command within a specific Readwise export — that also simply usesrefreshBookExport
notes about
refreshBookExport
refreshBookExport
will always trigger arequestArchive
(either directly or viastartSync
), regardless of if it was provided specific books to refresh, so new highlights should always appearnotes about "resync deleted files" (aka
settings.refreshBooks
):booksIDsMap
so we have a copy of its book IDbooksToRefresh
booksToRefresh
as they are deletedbooksIDsMap
refreshBookExport
will look for a difference in the filesystem vs what is inbooksIDsMap
— seemed like the only way to handle filesystem deletions (outside of Obsidian), unknown performance when there are many many readwise files. could be moved behind a toggle if it's particularly slow.other notes:
auto
query string seems to indicate that the sync wasn't triggered by a user (eg interval sync)settings.readwiseDir
isn't there, therequestArchive
will use theparentPageDeleted
querystring (like/api/obsidian/init?parentPageDeleted=true
) — there's no documentation on this, but i did test it and it does successfully sync the files in a clean installinstall for testing
you can download and build the plugin yourself, or use BRAT to install a pre-built beta:
https://github.com/tyler-dot-earth/dev-obsidian-readwise
Latest pre-built version:refactor-improve-sync-reliability-beta-1
Should look a bit like this:how to test thoroughly
[ ] confirm clean plugin install syncs notes as expected (this isn't automatic; you must click "initiate sync" or reload the workspace after authenticating)
enable
Resync deleted files
delete a synced file
use command palette to
Readwise Official: Sync your data now
[ ] confirm deleted file is re-synced
delete a synced file
open plugin settings and click
Initiate sync
[ ] confirm deleted file is re-synced
open a synced file
use command palette to
Readwise Official: Delete and reimport this document
[ ] confirm file is deleted and is re-synced
delete synced file
use command palette to
Reload app without saving
(or re-open Obsidian)[ ] confirm deleted file is re-synced
disable
Resync deleted files
delete a synced file
use command palette to
Readwise Official: Sync your data now
[ ] confirm file is NOT re-synced
delete a synced file
open plugin settings and click
Initiate sync
[ ] confirm file is NOT re-synced
open a synced file
use command palette to
Readwise Official: Delete and reimport this document
[ ] confirm file is re-synced
delete synced file
use command palette to
Reload app without saving
(or re-open Obsidian)[ ] confirm deleted file is re-synced
delete synced file
enable
Resync deleted files
[ ] confirm deleted file is re-synced
and finally, for good measure:
[ ] ensure adding new highlights continues to work as expected
[ ] ensure syncing on interval continues to work as expected
other changes