Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull apt updates less frequently #1790

Merged
merged 20 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e5066b9
Core/Client: Add UpdateCacheType
meisenzahl Dec 12, 2021
9532fd7
Application: Force a Flatpak cache refresh when the window opens, so …
meisenzahl Dec 12, 2021
06af06b
Pass update cache type to UpdateFailDialog
meisenzahl Dec 12, 2021
86ecdab
Rename UpdateCacheType to CacheUpdateType
meisenzahl Dec 12, 2021
1bb8e5e
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Dec 17, 2021
800ca35
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Dec 19, 2021
d1729e0
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Dec 29, 2021
2b5c696
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 2, 2022
989bc94
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 6, 2022
f5ab925
Merge branch 'master' into pull-apt-updates-less-frequently
cassidyjames Jan 6, 2022
c9ae3e8
Merge branch 'master' into pull-apt-updates-less-frequently
cassidyjames Jan 6, 2022
3155aac
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 7, 2022
b03774c
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 9, 2022
f1f616d
Merge branch 'master' into pull-apt-updates-less-frequently
danirabbit Jan 11, 2022
14e90fd
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 12, 2022
1123126
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 15, 2022
f555e36
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 16, 2022
e5acc89
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Jan 17, 2022
7701130
Merge branch 'master' into pull-apt-updates-less-frequently
meisenzahl Feb 26, 2022
491b61e
Merge branch 'master' into pull-apt-updates-less-frequently
danirabbit May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ public class AppCenter.App : Gtk.Application {
main_window = new MainWindow (this);


// Force a cache refresh when the window opens, so we get new apps
// Force a Flatpak cache refresh when the window opens, so we get new apps
#if HOMEPAGE
main_window.homepage_loaded.connect (() => {
client.update_cache.begin (true);
client.update_cache.begin (true, AppCenterCore.Client.CacheUpdateType.FLATPAK);
});
#else
client.update_cache.begin (true);
client.update_cache.begin (true, AppCenterCore.Client.CacheUpdateType.FLATPAK);
#endif

main_window.destroy.connect (() => {
Expand Down Expand Up @@ -332,13 +332,13 @@ public class AppCenter.App : Gtk.Application {
});
}

private void on_cache_update_failed (Error error) {
private void on_cache_update_failed (Error error, AppCenterCore.Client.CacheUpdateType cache_update_type) {
if (main_window == null) {
return;
}

if (update_fail_dialog == null) {
update_fail_dialog = new UpdateFailDialog (format_error_message (error.message));
update_fail_dialog = new UpdateFailDialog (format_error_message (error.message), cache_update_type);
update_fail_dialog.transient_for = main_window;

update_fail_dialog.destroy.connect (() => {
Expand Down
39 changes: 27 additions & 12 deletions src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class AppCenterCore.Client : Object {
public signal void operation_finished (Package package, Package.State operation, Error? error);
public signal void cache_update_failed (Error error);
public signal void cache_update_failed (Error error, CacheUpdateType cache_update_type);
/**
* This signal is likely to be fired from a non-main thread. Ensure any UI
* logic driven from this runs on the GTK thread
Expand Down Expand Up @@ -103,7 +103,7 @@ public class AppCenterCore.Client : Object {
}
}

public async void update_cache (bool force = false) {
public async void update_cache (bool force = false, CacheUpdateType cache_update_type = CacheUpdateType.ALL) {
cancellable.reset ();

debug ("update cache called %s", force.to_string ());
Expand Down Expand Up @@ -136,8 +136,16 @@ public class AppCenterCore.Client : Object {

refresh_in_progress = true;
try {
success = yield BackendAggregator.get_default ().refresh_cache (cancellable);
if (success) {
switch (cache_update_type) {
case CacheUpdateType.FLATPAK:
success = yield FlatpakBackend.get_default ().refresh_cache (cancellable);
break;
case CacheUpdateType.ALL:
success = yield BackendAggregator.get_default ().refresh_cache (cancellable);
break;
}

if (success && cache_update_type == CacheUpdateType.ALL) {
last_cache_update = new DateTime.now_utc ();
AppCenter.App.settings.set_int64 ("last-refresh-time", last_cache_update.to_unix ());
}
Expand All @@ -146,7 +154,7 @@ public class AppCenterCore.Client : Object {
} catch (Error e) {
if (!(e is GLib.IOError.CANCELLED)) {
critical ("Update_cache: Refesh cache async failed - %s", e.message);
cache_update_failed (e);
cache_update_failed (e, cache_update_type);
}
} finally {
refresh_in_progress = false;
Expand All @@ -160,14 +168,16 @@ public class AppCenterCore.Client : Object {
refresh_updates.begin ();
}

var next_refresh = SECONDS_BETWEEN_REFRESHES - (uint)seconds_since_last_refresh;
debug ("Setting a timeout for a refresh in %f minutes", next_refresh / 60.0f);
update_cache_timeout_id = GLib.Timeout.add_seconds (next_refresh, () => {
update_cache_timeout_id = 0;
update_cache.begin (true);
if (cache_update_type == CacheUpdateType.ALL) {
var next_refresh = SECONDS_BETWEEN_REFRESHES - (uint)seconds_since_last_refresh;
debug ("Setting a timeout for a refresh in %f minutes", next_refresh / 60.0f);
update_cache_timeout_id = GLib.Timeout.add_seconds (next_refresh, () => {
update_cache_timeout_id = 0;
update_cache.begin (true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another place that updating the entire cache happens? Looking only at the files that have changed does yield any results and so currently all I can see is that the only time a total update happens is when you've already called update_cache with the ALL type and it sets up the next_refresh timeout.


return GLib.Source.REMOVE;
});
return GLib.Source.REMOVE;
});
}
}

public Package? get_package_for_component_id (string id) {
Expand All @@ -186,4 +196,9 @@ public class AppCenterCore.Client : Object {
public static unowned Client get_default () {
return instance.once (() => { return new Client (); });
}

public enum CacheUpdateType {
FLATPAK,
ALL
}
}
8 changes: 5 additions & 3 deletions src/Dialogs/UpdateFailDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
public class UpdateFailDialog : Granite.MessageDialog {
private const int TRY_AGAIN_RESPONSE_ID = 1;
public string error_message { get; construct; }
public AppCenterCore.Client.CacheUpdateType cache_update_type { get; construct; }

public UpdateFailDialog (string error_message) {
public UpdateFailDialog (string error_message, AppCenterCore.Client.CacheUpdateType cache_update_type) {
Object (
title: "",
primary_text: _("Failed to Fetch Updates"),
secondary_text: _("This may have been caused by external, manually added software repositories or a corrupted sources file."),
image_icon: new ThemedIcon ("dialog-error"),
buttons: Gtk.ButtonsType.NONE,
error_message: error_message
error_message: error_message,
cache_update_type: cache_update_type
);
}

Expand All @@ -37,7 +39,7 @@ public class UpdateFailDialog : Granite.MessageDialog {

response.connect ((response_id) => {
if (response_id == TRY_AGAIN_RESPONSE_ID) {
AppCenterCore.Client.get_default ().update_cache.begin (true);
AppCenterCore.Client.get_default ().update_cache.begin (true, cache_update_type);
}
destroy ();
});
Expand Down