Keep a cache of session file data, and only write if changes occur #1316
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.
This is mainly in response to #1313, but making
session.save
less heavy in general has been something I've thought about, and this approach seemed simpler than trying to mark downloads as dirty or have logic depending on the state as described here. The overhead of a cache miss is pretty low, but rakshasa/libtorrent#257 was mainly to make this much more effective for libtorrent_resume files. I'm on the fence about whether this is an elegant use of cache or a terrible hack, so I submit it for your consideration.It includes two other changes to behavior:
.libtorrent_resume
to get updated while.rtorrent
doesn't. I couldn't think of a scenario where this would be bad, and it would've complicated error handling, but it can be done if desired.::access()
call is made on a cache hit. This is primarily to support the rare but important use case of being able to restore a session directory entirely from scratch on a running instance (e.g. if someone accidentally deletes it)Something to consider might be adding an override flag so that
d.save_full_session
andd.save_resume
can ignore the cache.