[gnome-photos/wip/rishi/collection: 31/45] item-manager: Try harder to not create an item if one already exists
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 31/45] item-manager: Try harder to not create an item if one already exists
- Date: Mon, 12 Feb 2018 11:36:21 +0000 (UTC)
commit 023fc702351a0815639b6cdc50b957a666b3eeb0
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Feb 6 00:34:16 2018 +0100
item-manager: Try harder to not create an item if one already exists
In the future, BaseItems that are created out-of-band, because they
aren't present in the child BaseManagers, should be cached. That would
ensure that there's only one BaseItem for a given URN in the Tracker
database.
https://gitlab.gnome.org/GNOME/gnome-photos/issues/29
src/photos-item-manager.c | 84 +++++++++++++++++++++++++++--------------------
1 file changed, 49 insertions(+), 35 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 08075685..a2cbfad1 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1361,8 +1361,9 @@ photos_item_manager_create_item (PhotosItemManager *self,
TrackerSparqlCursor *cursor,
gboolean create_thumbnails)
{
- GType type;
+ PhotosBaseItem *item;
PhotosBaseItem *ret_val = NULL;
+ const gchar *id;
g_return_val_if_fail (PHOTOS_IS_ITEM_MANAGER (self), NULL);
g_return_val_if_fail (base_item_type == G_TYPE_NONE
@@ -1370,52 +1371,65 @@ photos_item_manager_create_item (PhotosItemManager *self,
&& g_type_is_a (base_item_type, PHOTOS_TYPE_BASE_ITEM)), NULL);
g_return_val_if_fail (TRACKER_SPARQL_IS_CURSOR (cursor), NULL);
- if (base_item_type == G_TYPE_NONE)
+ id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
+ if (item != NULL)
{
- GIOExtension *extension;
- g_auto (GStrv) split_identifier = NULL;
- const gchar *extension_name = "local";
- g_autofree gchar *identifier = NULL;
+ ret_val = g_object_ref (item);
+ }
+ else
+ {
+ GType type;
- identifier = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER,
NULL));
- if (identifier != NULL)
+ if (base_item_type == G_TYPE_NONE)
{
- split_identifier = g_strsplit (identifier, ":", 4);
-
- if (photos_item_manager_cursor_is_collection (cursor))
+ GIOExtension *extension;
+ g_auto (GStrv) split_identifier = NULL;
+ const gchar *extension_name = "local";
+ g_autofree gchar *identifier = NULL;
+
+ identifier = g_strdup (tracker_sparql_cursor_get_string (cursor,
+ PHOTOS_QUERY_COLUMNS_IDENTIFIER,
+ NULL));
+ if (identifier != NULL)
{
- /* Its a collection. */
- extension_name = split_identifier[2];
+ split_identifier = g_strsplit (identifier, ":", 4);
+
+ if (photos_item_manager_cursor_is_collection (cursor))
+ {
+ /* Its a collection. */
+ extension_name = split_identifier[2];
+ }
+ else
+ {
+ /* Its a normal photo item. */
+ if (g_strv_length (split_identifier) > 1)
+ extension_name = split_identifier[0];
+ }
}
- else
+
+ extension = g_io_extension_point_get_extension_by_name (self->extension_point, extension_name);
+ if (G_UNLIKELY (extension == NULL))
{
- /* Its a normal photo item. */
- if (g_strv_length (split_identifier) > 1)
- extension_name = split_identifier[0];
+ g_warning ("Unable to find extension %s for identifier: %s", extension_name, identifier);
+ goto out;
}
- }
- extension = g_io_extension_point_get_extension_by_name (self->extension_point, extension_name);
- if (G_UNLIKELY (extension == NULL))
+ type = g_io_extension_get_type (extension);
+ }
+ else
{
- g_warning ("Unable to find extension %s for identifier: %s", extension_name, identifier);
- goto out;
+ type = base_item_type;
}
- type = g_io_extension_get_type (extension);
- }
- else
- {
- type = base_item_type;
- }
+ g_return_val_if_fail (type != G_TYPE_NONE, NULL);
+ g_return_val_if_fail (type != PHOTOS_TYPE_BASE_ITEM && g_type_is_a (type, PHOTOS_TYPE_BASE_ITEM),
NULL);
- g_return_val_if_fail (type != G_TYPE_NONE, NULL);
- g_return_val_if_fail (type != PHOTOS_TYPE_BASE_ITEM && g_type_is_a (type, PHOTOS_TYPE_BASE_ITEM), NULL);
-
- ret_val = PHOTOS_BASE_ITEM (g_object_new (type,
- "cursor", cursor,
- "failed-thumbnailing", !create_thumbnails,
- NULL));
+ ret_val = PHOTOS_BASE_ITEM (g_object_new (type,
+ "cursor", cursor,
+ "failed-thumbnailing", !create_thumbnails,
+ NULL));
+ }
out:
return ret_val;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]