[rygel] media-export: Avoid extra database query
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Avoid extra database query
- Date: Sat, 14 Aug 2010 23:31:55 +0000 (UTC)
commit d588393e11194761ae26e9548d6f39e80e492915
Author: Jens Georg <mail jensge org>
Date: Sun Aug 1 15:37:56 2010 +0200
media-export: Avoid extra database query
When checking for change conditions, avoid extra query for size-check.
Since push_if_changed_or_unknown will be called for MediaItems only,
there is no need for a left-outer join in the query.
.../rygel-media-export-harvesting-task.vala | 19 ++++---------------
.../rygel-media-export-media-cache.vala | 6 +++++-
.../rygel-media-export-sql-factory.vala | 4 +++-
3 files changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-harvesting-task.vala b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
index d9d6410..ffe38aa 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -126,28 +126,17 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine, GLib.Object
FileInfo info) {
var id = MediaCache.get_id (file);
int64 timestamp;
+ int64 size;
try {
- if (this.cache.exists (id, out timestamp)) {
+ if (this.cache.exists (id, out timestamp, out size)) {
int64 mtime = (int64) info.get_attribute_uint64 (
FILE_ATTRIBUTE_TIME_MODIFIED);
- // Doing the check for mtime here first because the check for
- // size involves a database query and if the size has changed,
- // the mtime probably has as well (unfortunatly enough
- // exceptions exist)
- if (mtime > timestamp) {
+ if (mtime > timestamp ||
+ info.get_size () != size) {
this.files.offer (file);
return true;
- } else {
- // check size
- var size = info.get_size ();
- var item = cache.get_item (id);
- if (item.size != size) {
- this.files.offer (file);
-
- return true;
- }
}
} else {
this.files.offer (file);
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 8aedae7..54c427a 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -154,22 +154,26 @@ public class Rygel.MediaExport.MediaCache : Object {
}
public bool exists (string object_id,
- out int64 timestamp) throws DatabaseError {
+ out int64 timestamp,
+ out int64 size) throws DatabaseError {
bool exists = false;
GLib.Value[] values = { object_id };
int64 tmp_timestamp = 0;
+ int64 tmp_size = 0;
this.db.exec (this.sql.make (SQLString.EXISTS),
values,
(statement) => {
exists = statement.column_int (0) == 1;
tmp_timestamp = statement.column_int64 (1);
+ tmp_size = statement.column_int64 (2);
return false;
});
// out parameters are not allowed to be captured
timestamp = tmp_timestamp;
+ size = tmp_size;
return exists;
}
diff --git a/src/plugins/media-export/rygel-media-export-sql-factory.vala b/src/plugins/media-export/rygel-media-export-sql-factory.vala
index 25eefd4..06c387f 100644
--- a/src/plugins/media-export/rygel-media-export-sql-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-sql-factory.vala
@@ -143,7 +143,9 @@ internal class Rygel.MediaExport.SQLFactory : Object {
"SELECT COUNT(upnp_id) FROM Object WHERE Object.parent = ?";
private const string OBJECT_EXISTS_STRING =
- "SELECT COUNT(upnp_id), timestamp FROM Object WHERE Object.upnp_id = ?";
+ "SELECT COUNT(upnp_id), timestamp, m.size FROM Object " +
+ "JOIN meta_data m ON m.object_fk = upnp_id " +
+ "WHERE Object.upnp_id = ?";
private const string GET_CHILD_ID_STRING =
"SELECT upnp_id FROM OBJECT WHERE parent = ?";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]