[gnome-photos/wip/rishi/import-8: 4/6] item-manager: Do 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/import-8: 4/6] item-manager: Do not create an item if one already exists
- Date: Thu, 15 Feb 2018 08:09:59 +0000 (UTC)
commit 11275fb7997f4f9fe4f62e9d9239fe95ae15b657
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Feb 6 00:34:16 2018 +0100
item-manager: Do not create an item if one already exists
The goal is to have only one BaseItem instance per Tracker URN per
SearchContext. However, that's not the case right now because
CollectionIconWatcher creates its own BaseItems to keep a collection's
thumbnail synchronized with its contents.
A subsequent commit will add a dialog to add items that are going to
be imported from an attached device to a collection. This dialog will
need a list of all collection BaseItems, which might exceed those that
are currently present in ItemManager and being rendered by the various
ViewContainers.
This is a good time to take a step towards the end goal of having only
one BaseItem instance per Tracker URN.
The easiest thing to do is to not create a new BaseItem if one already
exists in ItemManager. This also doesn't involve any complication
around whether to initiate thumbnailing or not because the dialog
doesn't require thumbnails anyway and would just re-use whatever is
already available.
In the future, BaseItems that are created out-of-band should be
cached. However, that would require carefully deciding whether and
when to initiate thumbnailing or not.
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 db97a19a..4dea5800 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1287,8 +1287,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
@@ -1296,52 +1297,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]