[gnome-games/wip/exalm/cache2: 45/45] grilo: Queue loading
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 45/45] grilo: Queue loading
- Date: Mon, 8 Oct 2018 22:37:43 +0000 (UTC)
commit d6c2b661a15996b4f45503fb0655525702234079
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 07393b10..6439b1f3 100644
--- a/src/grilo/grilo-cooperative.vala
+++ b/src/grilo/grilo-cooperative.vala
@@ -18,7 +18,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 5b97f02b..eb3bbf14 100644
--- a/src/grilo/grilo-description.vala
+++ b/src/grilo/grilo-description.vala
@@ -18,7 +18,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 5b1ae94a..5e56fdab 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 2aa3e24b..28ecbb0b 100644
--- a/src/grilo/grilo-genre.vala
+++ b/src/grilo/grilo-genre.vala
@@ -18,7 +18,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 0cb69d6e..94f3744d 100644
--- a/src/grilo/grilo-players.vala
+++ b/src/grilo/grilo-players.vala
@@ -18,7 +18,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 035ce95c..3c842469 100644
--- a/src/grilo/grilo-publisher.vala
+++ b/src/grilo/grilo-publisher.vala
@@ -18,7 +18,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 4a3a6741..3d1adbfb 100644
--- a/src/grilo/grilo-rating.vala
+++ b/src/grilo/grilo-rating.vala
@@ -18,7 +18,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 1be39328..7e309b49 100644
--- a/src/grilo/grilo-release-date.vala
+++ b/src/grilo/grilo-release-date.vala
@@ -18,7 +18,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]