[gnome-games/wip/exalm/issue100: 2/2] local-cover: Revert async loading



commit 723761e221584ac5e8bfb9fc9dd4321b3a2cad77
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Aug 19 15:27:55 2018 +0500

    local-cover: Revert async loading
    
    Async loading should in theory speed up collection loading, but it leads
    to a situation where both local and remote covers start loading at once,
    significantly slowing down loading of collections where most games have
    local covers, and wasting traffic unnecessarily. So let's revert it for
    now.
    
    Reverts commit 54213ae2f0bff819d61977b0ff26682f2ed1906f.

 src/utils/local-cover.vala | 64 ++++++++++++++++------------------------------
 1 file changed, 22 insertions(+), 42 deletions(-)
---
diff --git a/src/utils/local-cover.vala b/src/utils/local-cover.vala
index 226288cf..1190be58 100644
--- a/src/utils/local-cover.vala
+++ b/src/utils/local-cover.vala
@@ -2,61 +2,51 @@
 
 public class Games.LocalCover : Object, Cover {
        private Uri uri;
+       private bool resolved;
        private GLib.Icon? icon;
-       private bool resolving;
-       private string? cover_path;
 
        public LocalCover (Uri uri) {
                this.uri = uri;
-               resolving = false;
        }
 
        public GLib.Icon? get_cover () {
-               if (resolving)
+               if (resolved)
                        return icon;
 
-               if (icon != null)
-                       return icon;
+               resolved = true;
 
+               string? cover_path;
                try {
-                       load_cover ();
+                       cover_path = get_cover_path ();
                }
                catch (Error e) {
                        warning (e.message);
 
-                       return icon;
+                       return null;
                }
 
-               if (icon != null)
-                       return icon;
-
-               resolving = true;
+               if (cover_path == null)
+                       return null;
 
-               try_resolve_path.begin ();
+               var file = File.new_for_path (cover_path);
+               icon = new FileIcon (file);
 
                return icon;
        }
 
-       private async void try_resolve_path () throws Error {
-               cover_path = yield get_sibbling_cover_path ();
-               if (cover_path != null && FileUtils.test (cover_path, FileTest.EXISTS)) {
-                       load_cover ();
-
-                       return;
-               }
-
-               cover_path = yield get_directory_cover_path ();
-               if (cover_path != null && FileUtils.test (cover_path, FileTest.EXISTS)) {
-                       load_cover ();
+       private string? get_cover_path () throws Error {
+               var cover_path = get_sibbling_cover_path ();
+               if (cover_path != null && FileUtils.test (cover_path, FileTest.EXISTS))
+                       return cover_path;
 
-                       return;
-               }
+               cover_path = get_directory_cover_path ();
+               if (cover_path != null && FileUtils.test (cover_path, FileTest.EXISTS))
+                       return cover_path;
 
-               cover_path = null;
-               load_cover ();
+               return null;
        }
 
-       private async string? get_sibbling_cover_path () throws Error {
+       private string? get_sibbling_cover_path () throws Error {
                var file = uri.to_file ();
                var parent = file.get_parent ();
                if (parent == null)
@@ -69,7 +59,7 @@ public class Games.LocalCover : Object, Cover {
                string cover_path = null;
                var directory = new Directory (parent);
                var attributes = string.join (",", FileAttribute.STANDARD_NAME, 
FileAttribute.STANDARD_FAST_CONTENT_TYPE);
-               yield directory.foreach_async (attributes, (sibbling) => {
+               directory.foreach (attributes, (sibbling) => {
                        var sibbling_basename = sibbling.get_name ();
                        if (sibbling_basename == basename)
                                return false;
@@ -90,7 +80,7 @@ public class Games.LocalCover : Object, Cover {
                return cover_path;
        }
 
-       private async string? get_directory_cover_path () throws Error {
+       private string? get_directory_cover_path () throws Error {
                var file = uri.to_file ();
                var parent = file.get_parent ();
                if (parent == null)
@@ -99,7 +89,7 @@ public class Games.LocalCover : Object, Cover {
                string cover_path = null;
                var directory = new Directory (parent);
                var attributes = string.join (",", FileAttribute.STANDARD_NAME, 
FileAttribute.STANDARD_FAST_CONTENT_TYPE);
-               yield directory.foreach_async (attributes, (sibbling) => {
+               directory.foreach (attributes, (sibbling) => {
                        var sibbling_basename = sibbling.get_name ();
                        if (!sibbling_basename.has_prefix ("cover.") &&
                            !sibbling_basename.has_prefix ("folder."))
@@ -117,14 +107,4 @@ public class Games.LocalCover : Object, Cover {
 
                return cover_path;
        }
-
-       private void load_cover () throws Error {
-               if (cover_path == null || !FileUtils.test (cover_path, FileTest.EXISTS))
-                       return;
-
-               var file = File.new_for_path (cover_path);
-               icon = new FileIcon (file);
-
-               changed ();
-       }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]