[gnome-games/wip/exalm/cache2: 27/27] grilo: Queue loading
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 27/27] grilo: Queue loading
- Date: Sun, 7 Oct 2018 10:25:20 +0000 (UTC)
commit d45773fbe359d07cb90b3020809fa19c98ef843a
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sat Oct 6 20:00:58 2018 +0500
grilo: Queue loading
Put all GriloMedia requests into a global queue and process them one by
one. This allows to avoid UI stalling while loading metadata for many
games at once at a cost of it taking longer time.
src/grilo/grilo-cooperative.vala | 2 +-
src/grilo/grilo-cover.vala | 2 +-
src/grilo/grilo-description.vala | 2 +-
src/grilo/grilo-developer.vala | 2 +-
src/grilo/grilo-genre.vala | 2 +-
src/grilo/grilo-media-queue.vala | 36 ++++++++++++++++++++++++++++++++++++
src/grilo/grilo-media.vala | 10 ++++++++++
src/grilo/grilo-players.vala | 2 +-
src/grilo/grilo-publisher.vala | 2 +-
src/grilo/grilo-rating.vala | 2 +-
src/grilo/grilo-release-date.vala | 2 +-
src/meson.build | 1 +
12 files changed, 56 insertions(+), 9 deletions(-)
---
diff --git a/src/grilo/grilo-cooperative.vala b/src/grilo/grilo-cooperative.vala
index 808c78f4..72aef355 100644
--- a/src/grilo/grilo-cooperative.vala
+++ b/src/grilo/grilo-cooperative.vala
@@ -19,7 +19,7 @@ public class Games.GriloCooperative : Object, Cooperative {
return cooperative;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return cooperative;
}
diff --git a/src/grilo/grilo-cover.vala b/src/grilo/grilo-cover.vala
index 5736237e..db53bc09 100644
--- a/src/grilo/grilo-cover.vala
+++ b/src/grilo/grilo-cover.vala
@@ -35,7 +35,7 @@ public class Games.GriloCover : Object, Cover {
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return icon;
}
diff --git a/src/grilo/grilo-description.vala b/src/grilo/grilo-description.vala
index 87ccdfe3..7abae3da 100644
--- a/src/grilo/grilo-description.vala
+++ b/src/grilo/grilo-description.vala
@@ -22,7 +22,7 @@ public class Games.GriloDescription : Object, Description {
return description;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return description;
}
diff --git a/src/grilo/grilo-developer.vala b/src/grilo/grilo-developer.vala
index 83118b76..1ca7abf2 100644
--- a/src/grilo/grilo-developer.vala
+++ b/src/grilo/grilo-developer.vala
@@ -18,7 +18,7 @@ public class Games.GriloDeveloper : Object, Developer {
return developer;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return developer;
}
diff --git a/src/grilo/grilo-genre.vala b/src/grilo/grilo-genre.vala
index da3a7925..87a01633 100644
--- a/src/grilo/grilo-genre.vala
+++ b/src/grilo/grilo-genre.vala
@@ -22,7 +22,7 @@ public class Games.GriloGenre : Object, Genre {
return genre;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return genre;
}
diff --git a/src/grilo/grilo-media-queue.vala b/src/grilo/grilo-media-queue.vala
new file mode 100644
index 00000000..5c9ec814
--- /dev/null
+++ b/src/grilo/grilo-media-queue.vala
@@ -0,0 +1,36 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.GriloMediaQueue : Object {
+ private Queue<GriloMedia> queue;
+ private GriloMedia current_media;
+
+ private static Once<GriloMediaQueue> instance;
+
+ construct {
+ queue = new Queue<GriloMedia> ();
+ }
+
+ private static GriloMediaQueue create_instance () {
+ return new GriloMediaQueue ();
+ }
+
+ public static unowned GriloMediaQueue get_instance () {
+ return instance.once (create_instance);
+ }
+
+ public void append (GriloMedia media) {
+ queue.push_tail (media);
+
+ if (current_media == null)
+ load_next_media ();
+ }
+
+ private void load_next_media () {
+ if (queue.is_empty ())
+ return;
+
+ current_media = queue.pop_head ();
+ current_media.resolved.connect (load_next_media);
+ current_media.try_resolve_media ();
+ }
+}
diff --git a/src/grilo/grilo-media.vala b/src/grilo/grilo-media.vala
index 738cb710..9cec6da9 100644
--- a/src/grilo/grilo-media.vala
+++ b/src/grilo/grilo-media.vala
@@ -14,6 +14,8 @@ public class Games.GriloMedia : Object {
private Grl.Media? media;
+ private bool queued;
+
public GriloMedia (Title title, string mime_type) {
this.title = title;
this.mime_type = mime_type;
@@ -51,6 +53,14 @@ public class Games.GriloMedia : Object {
}
}
+ public void try_resolve_media_queued () {
+ if (queued)
+ return;
+
+ GriloMediaQueue.get_instance ().append (this);
+ queued = true;
+ }
+
internal Grl.Media? get_media () {
return media;
}
diff --git a/src/grilo/grilo-players.vala b/src/grilo/grilo-players.vala
index 864546a7..1ce76916 100644
--- a/src/grilo/grilo-players.vala
+++ b/src/grilo/grilo-players.vala
@@ -22,7 +22,7 @@ public class Games.GriloPlayers : Object, Players {
return players;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return players;
}
diff --git a/src/grilo/grilo-publisher.vala b/src/grilo/grilo-publisher.vala
index fa656081..dcd43a54 100644
--- a/src/grilo/grilo-publisher.vala
+++ b/src/grilo/grilo-publisher.vala
@@ -22,7 +22,7 @@ public class Games.GriloPublisher : Object, Publisher {
return publisher;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return publisher;
}
diff --git a/src/grilo/grilo-rating.vala b/src/grilo/grilo-rating.vala
index 4a6e18b1..20ed0ff9 100644
--- a/src/grilo/grilo-rating.vala
+++ b/src/grilo/grilo-rating.vala
@@ -19,7 +19,7 @@ public class Games.GriloRating : Object, Rating {
return rating;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return rating;
}
diff --git a/src/grilo/grilo-release-date.vala b/src/grilo/grilo-release-date.vala
index 30de60b8..ae4c9a23 100644
--- a/src/grilo/grilo-release-date.vala
+++ b/src/grilo/grilo-release-date.vala
@@ -22,7 +22,7 @@ public class Games.GriloReleaseDate : Object, ReleaseDate {
return release_date;
resolving = true;
- media.try_resolve_media ();
+ media.try_resolve_media_queued ();
return release_date;
}
diff --git a/src/meson.build b/src/meson.build
index 2bb73e11..8e9882f0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -106,6 +106,7 @@ vala_sources = [
'grilo/grilo-developer.vala',
'grilo/grilo-genre.vala',
'grilo/grilo-media.vala',
+ 'grilo/grilo-media-queue.vala',
'grilo/grilo-players.vala',
'grilo/grilo-publisher.vala',
'grilo/grilo-rating.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]