[gnome-games/wip/exalm/cache2: 21/28] database: Cache Description
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 21/28] database: Cache Description
- Date: Sun, 7 Oct 2018 17:59:25 +0000 (UTC)
commit 3af55299da4e359084fcc7e825a862f9a2a16915
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Tue Oct 2 19:30:34 2018 +0500
database: Cache Description
src/database/database-description.vala | 26 +++++++++++++++
src/database/database-game.vala | 4 ++-
src/database/database-metadata.vala | 58 ++++++++++++++++++++++++++++++++--
src/database/database.vala | 1 +
src/meson.build | 1 +
5 files changed, 87 insertions(+), 3 deletions(-)
---
diff --git a/src/database/database-description.vala b/src/database/database-description.vala
new file mode 100644
index 00000000..7c786ff8
--- /dev/null
+++ b/src/database/database-description.vala
@@ -0,0 +1,26 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.DatabaseDescription : Object, Description {
+ private DatabaseMetadata metadata;
+
+ public bool has_loaded { get; protected set; }
+
+ public DatabaseDescription (DatabaseMetadata metadata) {
+ this.metadata = metadata;
+
+ if (metadata.description_loaded)
+ has_loaded = true;
+ else {
+ metadata.notify["description-loaded"].connect (on_description_loaded);
+ metadata.get_description ();
+ }
+ }
+
+ private void on_description_loaded (Object object, ParamSpec param) {
+ has_loaded = metadata.description_loaded;
+ }
+
+ public string get_description () {
+ return metadata.get_description ();
+ }
+}
diff --git a/src/database/database-game.vala b/src/database/database-game.vala
index a98893f1..fffdb776 100644
--- a/src/database/database-game.vala
+++ b/src/database/database-game.vala
@@ -9,6 +9,7 @@ private class Games.DatabaseGame : Object, Game {
private Game game;
private Cooperative cooperative;
+ private Description description;
private Developer developer;
public DatabaseGame (Database database, Game game) {
@@ -18,6 +19,7 @@ private class Games.DatabaseGame : Object, Game {
var metadata = database.get_metadata (game);
cooperative = new DatabaseCooperative (metadata);
+ description = new DatabaseDescription (metadata);
developer = new DatabaseDeveloper (metadata);
}
@@ -58,7 +60,7 @@ private class Games.DatabaseGame : Object, Game {
}
public Description get_description () {
- return game.get_description ();
+ return description;
}
public Rating get_rating () {
diff --git a/src/database/database-metadata.vala b/src/database/database-metadata.vala
index 5d62a2e2..d15ef0e8 100644
--- a/src/database/database-metadata.vala
+++ b/src/database/database-metadata.vala
@@ -2,7 +2,11 @@
private class Games.DatabaseMetadata : Object {
private const string LOAD_QUERY = """
- SELECT cooperative, developer FROM game_metadata WHERE uid=$UID;
+ SELECT
+ cooperative,
+ description,
+ developer
+ FROM game_metadata WHERE uid=$UID;
""";
private const string ADD_GAME_QUERY = """
@@ -13,6 +17,10 @@ private class Games.DatabaseMetadata : Object {
UPDATE game_metadata SET cooperative=$COOPERATIVE WHERE uid=$UID;
""";
+ private const string SAVE_DESCRIPTION_QUERY = """
+ UPDATE game_metadata SET description=$DESCRIPTION WHERE uid=$UID;
+ """;
+
private const string SAVE_DEVELOPER_QUERY = """
UPDATE game_metadata SET developer=$DEVELOPER WHERE uid=$UID;
""";
@@ -20,18 +28,22 @@ private class Games.DatabaseMetadata : Object {
private Game game;
private Uid uid;
private Cooperative cooperative;
+ private Description description;
private Developer developer;
private string uid_value;
private bool cooperative_value;
+ private string description_value;
private string developer_value;
private Sqlite.Statement add_game_statement;
private Sqlite.Statement load_statement;
private Sqlite.Statement save_cooperative_statement;
+ private Sqlite.Statement save_description_statement;
private Sqlite.Statement save_developer_statement;
public bool cooperative_loaded { get; set; }
+ public bool description_loaded { get; set; }
public bool developer_loaded { get; set; }
private bool game_added;
@@ -41,6 +53,7 @@ private class Games.DatabaseMetadata : Object {
uid = game.get_uid ();
cooperative = game.get_cooperative ();
+ description = game.get_description ();
developer = game.get_developer ();
try {
@@ -49,6 +62,7 @@ private class Games.DatabaseMetadata : Object {
add_game_statement = Database.prepare (database, ADD_GAME_QUERY);
load_statement = Database.prepare (database, LOAD_QUERY);
save_cooperative_statement = Database.prepare (database, SAVE_COOPERATIVE_QUERY);
+ save_description_statement = Database.prepare (database, SAVE_DESCRIPTION_QUERY);
save_developer_statement = Database.prepare (database, SAVE_DEVELOPER_QUERY);
load_metadata ();
@@ -68,6 +82,16 @@ private class Games.DatabaseMetadata : Object {
return cooperative_value;
}
+ public string get_description () {
+ if (!description_loaded) {
+ on_description_loaded ();
+ description.notify.connect (on_description_loaded);
+ return description.get_description ();
+ }
+
+ return description_value;
+ }
+
public string get_developer () {
if (!developer_loaded) {
on_developer_loaded ();
@@ -89,6 +113,17 @@ private class Games.DatabaseMetadata : Object {
save_cooperative ();
}
+ private void on_description_loaded () {
+ if (!description.has_loaded)
+ return;
+
+ description_value = description.get_description ();
+ description_loaded = true;
+
+ add_game ();
+ save_description ();
+ }
+
private void on_developer_loaded () {
if (!developer.has_loaded)
return;
@@ -114,6 +149,20 @@ private class Games.DatabaseMetadata : Object {
}
}
+ private void save_description () {
+ try {
+ save_description_statement.reset ();
+ Database.bind_text (save_description_statement, "$UID", uid_value);
+ Database.bind_text (save_description_statement, "$DESCRIPTION", description_value);
+
+ if (save_description_statement.step () != Sqlite.DONE)
+ warning ("Execution failed.");
+ }
+ catch (Error e) {
+ warning (e.message);
+ }
+ }
+
private void save_developer () {
try {
save_developer_statement.reset ();
@@ -159,7 +208,12 @@ private class Games.DatabaseMetadata : Object {
}
if (load_statement.column_type (1) != Sqlite.NULL) {
- developer_value = load_statement.column_text (1);
+ description_value = load_statement.column_text (1);
+ description_loaded = true;
+ }
+
+ if (load_statement.column_type (2) != Sqlite.NULL) {
+ developer_value = load_statement.column_text (2);
developer_loaded = true;
}
}
diff --git a/src/database/database.vala b/src/database/database.vala
index 57c3c8a2..431f0096 100644
--- a/src/database/database.vala
+++ b/src/database/database.vala
@@ -22,6 +22,7 @@ private class Games.Database : Object {
CREATE TABLE IF NOT EXISTS game_metadata (
uid TEXT PRIMARY KEY NOT NULL,
cooperative INTEGER,
+ description TEXT,
developer TEXT
) WITHOUT ROWID;
""";
diff --git a/src/meson.build b/src/meson.build
index a2c72691..cf195219 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -47,6 +47,7 @@ vala_sources = [
'database/database.vala',
'database/database-cooperative.vala',
+ 'database/database-description.vala',
'database/database-developer.vala',
'database/database-error.vala',
'database/database-game.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]