Skip to content

Commit a33face

Browse files
Prepare speed up (#2419)
* FlatpakBackend: Fix identifying main thread * Add normalize_component_id Utils function --------- Co-authored-by: Danielle Foré <danielle@elementary.io>
1 parent 87ae37b commit a33face

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/Core/FlatpakBackend.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ public class AppCenterCore.FlatpakBackend : Object, Backend {
13331333

13341334
package_list = new_package_list;
13351335

1336-
if (MainContext.get_thread_default () == null) {
1336+
if (Thread.self<bool> () != worker_thread) {
13371337
// We are in the main thread so update immediately
13381338
update_package_store (removed, added);
13391339
} else {

src/Core/Package.vala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ public class AppCenterCore.Package : Object {
147147
return _component_id;
148148
}
149149

150-
_component_id = component.id;
151-
if (_component_id.has_suffix (".desktop")) {
152-
// ".desktop" is always 8 bytes in UTF-8 so we can just chop 8 bytes off the end
153-
_component_id = _component_id.substring (0, _component_id.length - 8);
154-
}
150+
_component_id = Utils.normalize_component_id (component.id);
155151

156152
return _component_id;
157153
}

src/Utils.vala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,13 @@ namespace Utils {
8383
public static bool is_running_in_guest_session () {
8484
return Environment.get_user_name ().has_prefix ("guest-");
8585
}
86+
87+
public static string normalize_component_id (string component_id) {
88+
if (component_id.has_suffix (".desktop")) {
89+
// ".desktop" is always 8 bytes in UTF-8 so we can just chop 8 bytes off the end
90+
return component_id.substring (0, component_id.length - 8);
91+
}
92+
93+
return component_id;
94+
}
8695
}

0 commit comments

Comments
 (0)