Merge lp:~tintou/appcenter/optimizations into lp:~ricotz/appcenter/optimizations

Proposed by Corentin Noël
Status: Needs review
Proposed branch: lp:~tintou/appcenter/optimizations
Merge into: lp:~ricotz/appcenter/optimizations
Diff against target: 36 lines (+8/-9)
1 file modified
src/Core/Package.vala (+8/-9)
To merge this branch: bzr merge lp:~tintou/appcenter/optimizations
Reviewer Review Type Date Requested Status
Rico Tzschichholz Pending
Review via email: mp+309464@code.launchpad.net

Description of the change

I think it's better like this, tell me if it's a bad idea

To post a comment you must log in.
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

The boolean variable is not meant to catch race-conditions with threads, but simply the case if there is no matching package found or an error occurred, which the API suggests could happen.

If this function gets actually called in a multi-threaded environment adding a lock would make sense though.

Revision history for this message
Zisu Andrei (matzipan) wrote :

Rejecting as per Rico's comment.

Revision history for this message
Zisu Andrei (matzipan) wrote :

Whoops. Appears I can't do that myself. Rico?

Unmerged revisions

331. By Corentin Noël

Use existing variables.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Core/Package.vala'
2--- src/Core/Package.vala 2016-10-26 14:24:07 +0000
3+++ src/Core/Package.vala 2016-10-27 12:59:03 +0000
4@@ -40,7 +40,6 @@
5 public State state { public get; private set; default = State.NOT_INSTALLED; }
6
7 private Pk.Package? package = null;
8- private bool package_retrieved = false;
9
10 public double progress {
11 get {
12@@ -289,16 +288,16 @@
13 return null;
14 }
15
16- if (package_retrieved)
17- return package;
18-
19- try {
20- package = AppCenterCore.Client.get_default ().get_app_package (component.get_pkgnames ()[0], 0LL);
21- } catch (Error e) {
22- critical (e.message);
23+ lock (package) {
24+ if (package == null) {
25+ try {
26+ package = AppCenterCore.Client.get_default ().get_app_package (component.get_pkgnames ()[0], 0LL);
27+ } catch (Error e) {
28+ critical (e.message);
29+ }
30+ }
31 }
32
33- package_retrieved = true;
34 return package;
35 }
36 }

Subscribers

People subscribed via source and target branches