Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Remove spring cleaning from saved state
Browse files Browse the repository at this point in the history
The DB vacuum isn't a persistent operation, and it should just restart
next time if it's interrupted. This should fix an issue where if the
spring cleaning was interrupted, it would hang forever.

See #730
  • Loading branch information
brendanlong committed Nov 8, 2018
1 parent f67f06e commit 29819e0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 69 deletions.
10 changes: 1 addition & 9 deletions schemas/org.gnome.feedreader.saved-state.gschema.xml
Expand Up @@ -21,7 +21,7 @@
<default>false</default>
<summary>if window is maximized</summary>
<description>
Weather the window was maximized on close so it can be restored in the same way on startup.
Whether the window was maximized on close so it can be restored in the same way on startup.
</description>
</key>

Expand Down Expand Up @@ -115,14 +115,6 @@
</description>
</key>

<key name="spring-cleaning" type="b">
<default>false</default>
<summary>Clean up the DB</summary>
<description>
Do a vacuum of the db. No other operation can access the db during this.
</description>
</key>

<key name="last-spring-cleaning" type="i">
<default>946684800</default>
<summary>timestamp of the last spring cleaning</summary>
Expand Down
101 changes: 54 additions & 47 deletions src/Backend/Backend.vala
Expand Up @@ -25,6 +25,7 @@ namespace FeedReader {
private bool m_offline = true;
private bool m_cacheSync = false;
private uint m_timeout_source_id = 0;
private Mutex m_sync_lock;
private delegate void asyncPayload();

public signal void syncStarted();
Expand Down Expand Up @@ -185,62 +186,69 @@ namespace FeedReader {

private void sync(bool initSync = false, GLib.Cancellable? cancellable = null)
{
if(Settings.state().get_boolean("currently-updating")
|| Settings.state().get_boolean("spring-cleaning"))
// Prevent multiple concurrent syncs or spring cleanings
// We would prefer to use MutexLocker but it doesn't seem to work
m_sync_lock.lock();
try
{
Logger.debug("Cant sync because login failed or sync/clean already ongoing");
return;
}
if(Settings.state().get_boolean("currently-updating"))
{
Logger.debug("Cant sync because login failed or sync/clean already ongoing");
return;
}

if(Utils.springCleaningNecessary())
{
Logger.info("backend: spring cleaning");
Settings.state().set_boolean("spring-cleaning", true);
springCleanStarted();
DataBase.writeAccess().springCleaning();
Settings.state().set_boolean("spring-cleaning", false);
springCleanFinished();
}
if(Utils.springCleaningNecessary())
{
Logger.info("backend: spring cleaning");
springCleanStarted();
DataBase.writeAccess().springCleaning();
springCleanFinished();
}

if(cancellable != null && cancellable.is_cancelled())
return;
if(cancellable != null && cancellable.is_cancelled())
return;

Logger.info("backend: sync started");
syncStarted();
Settings.state().set_boolean("currently-updating", true);
Logger.info("backend: sync started");
syncStarted();
Settings.state().set_boolean("currently-updating", true);

if(!checkOnline())
{
Logger.info("Cancelling sync because we're not online");
finishSync();
return;
}
if(!checkOnline())
{
Logger.info("Cancelling sync because we're not online");
finishSync();
return;
}

if(cancellable != null && cancellable.is_cancelled())
{
finishSync();
return;
}
if(cancellable != null && cancellable.is_cancelled())
{
finishSync();
return;
}

m_cacheSync = true;
m_cacheSync = true;

if(initSync && FeedServer.get_default().doInitSync())
FeedServer.get_default().InitSyncContent(cancellable);
else
FeedServer.get_default().syncContent(cancellable);
if(initSync && FeedServer.get_default().doInitSync())
FeedServer.get_default().InitSyncContent(cancellable);
else
FeedServer.get_default().syncContent(cancellable);

if(cancellable != null && cancellable.is_cancelled())
{
finishSync();
return;
}

if(cancellable != null && cancellable.is_cancelled())
updateBadge();
m_cacheSync = false;
FeedServer.get_default().grabContent.begin(cancellable, (obj, res) => {
FeedServer.get_default().grabContent.end(res);
finishSync();
});
}
finally
{
finishSync();
return;
m_sync_lock.unlock();
}

updateBadge();
m_cacheSync = false;
FeedServer.get_default().grabContent.begin(cancellable, (obj, res) => {
FeedServer.get_default().grabContent.end(res);
finishSync();
});
}

private void finishSync()
Expand Down Expand Up @@ -761,8 +769,7 @@ namespace FeedReader {
public void updateBadge()
{
#if LIBUNITY
if(!Settings.state().get_boolean("spring-cleaning")
&& Settings.tweaks().get_boolean("show-badge"))
if(Settings.tweaks().get_boolean("show-badge"))
{
var count = DataBase.readOnly().get_unread_total();
Logger.debug("backend: update badge count %u".printf(count));
Expand Down
19 changes: 6 additions & 13 deletions src/Widgets/MainWindow.vala
Expand Up @@ -149,24 +149,17 @@ public class FeedReader.MainWindow : Gtk.ApplicationWindow
this.show_all();

Logger.debug("MainWindow: determining state");
if(FeedReaderBackend.get_default().isOnline() && !Settings.state().get_boolean("spring-cleaning"))
if(FeedReaderBackend.get_default().isOnline())
{
loadContent();
}
else if(!DataBase.readOnly().isEmpty())
{
showOfflineContent();
}
else
{
if(Settings.state().get_boolean("spring-cleaning"))
{
showSpringClean();
}
else if(!DataBase.readOnly().isEmpty())
{
showOfflineContent();
}
else
{
showLogin();
}
showLogin();
}
}

Expand Down

0 comments on commit 29819e0

Please sign in to comment.