From 4fcdd8c4a6c156eca2ea0466b6a342681fcab856 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 17 Aug 2015 05:42:37 -0400 Subject: [PATCH] 8377: cache path --- gramps/gui/views/treemodels/basemodel.py | 17 +++++++++++++++++ gramps/gui/views/treemodels/treebasemodel.py | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gramps/gui/views/treemodels/basemodel.py b/gramps/gui/views/treemodels/basemodel.py index ea088bc56..f9df3eb10 100644 --- a/gramps/gui/views/treemodels/basemodel.py +++ b/gramps/gui/views/treemodels/basemodel.py @@ -34,11 +34,13 @@ class BaseModel(object): def __init__(self): self.lru_data = LRU(BaseModel._CACHE_SIZE) + self.lru_path = LRU(BaseModel._CACHE_SIZE) def destroy(self): """ """ self.lru_data = None + self.lru_path = None def clear_cache(self, handle=None): """ @@ -49,6 +51,8 @@ class BaseModel(object): del self.lru_data[handle] else: self.lru_data.clear() + # Invalidates all paths + self.lru_path.clear() def get_cached_value(self, handle, col): """ @@ -64,4 +68,17 @@ class BaseModel(object): if handle not in self.lru_data: self.lru_data[handle] = {} self.lru_data[handle][col] = data + + ## Cached Path's for TreeView: + def get_cached_path(self, handle): + """ + """ + if handle in self.lru_path: + return (True, self.lru_path[handle]) + return (False, None) + def set_cached_path(self, handle, path): + """ + """ + if not self._in_build: + self.lru_path[handle] = path diff --git a/gramps/gui/views/treemodels/treebasemodel.py b/gramps/gui/views/treemodels/treebasemodel.py index 9e8bd6df8..ff99ab487 100644 --- a/gramps/gui/views/treemodels/treebasemodel.py +++ b/gramps/gui/views/treemodels/treebasemodel.py @@ -966,6 +966,9 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel): """ Returns a path from a given node. """ + cached, value = self.get_cached_path(iter.user_data) + if cached: + return value node = self.get_node_from_iter(iter) pathlist = [] while node.parent is not None: @@ -978,12 +981,13 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel): index += 1 pathlist.append(index) node = parent - if pathlist: pathlist.reverse() - return Gtk.TreePath(tuple(pathlist)) + retval = Gtk.TreePath(tuple(pathlist)) else: - return None + retval = None + self.set_cached_path(iter.user_data, retval) + return retval def do_iter_next(self, iter): """