diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-05-31 16:14:33 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-05-31 16:19:57 +0900 |
| commit | 631f37433a8fda03eb057e9f01e2811111c60d5e (patch) | |
| tree | 5423c539ab253a6249b0bce5e42ba6fe69b0c45d /src/SaveSessionCommand.cc | |
| parent | 998fba3264c1e896a249f140cb6060cc35c7d6bc (diff) | |
Save session only when there is change since the last serialization
This is a slight optimization not to cause useless disk access. This
only applies to saving session automatically (see
--save-session-interval). aria2.saveSession and serialization at the
end of the session are always performed as before.
When serialization, we first check that whether there is any change
since the last serialization. To do this, we first calculate hash
value of serialized content without writing into file. Then compare
this value to the value of last serialization. If they do not match,
perform serialization.
Diffstat (limited to 'src/SaveSessionCommand.cc')
| -rw-r--r-- | src/SaveSessionCommand.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SaveSessionCommand.cc b/src/SaveSessionCommand.cc index d94815ad..a3b12e54 100644 --- a/src/SaveSessionCommand.cc +++ b/src/SaveSessionCommand.cc @@ -63,8 +63,19 @@ void SaveSessionCommand::process() const std::string& filename = getDownloadEngine()->getOption() ->get(PREF_SAVE_SESSION); if(!filename.empty()) { - SessionSerializer sessionSerializer(getDownloadEngine()-> - getRequestGroupMan().get()); + auto& rgman = getDownloadEngine()->getRequestGroupMan(); + + SessionSerializer sessionSerializer(rgman.get()); + + auto sessionHash = sessionSerializer.calculateHash(); + if(rgman->getLastSessionHash() == sessionHash) { + A2_LOG_INFO("No change since last serialization or startup. " + "No serialization is necessary this time."); + return; + } + + rgman->setLastSessionHash(std::move(sessionHash)); + if(sessionSerializer.save(filename)) { A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), filename.c_str())); |
