8377: cache path

This commit is contained in:
Doug Blank 2015-08-17 05:42:37 -04:00
parent 12e9764fdd
commit 4fcdd8c4a6
2 changed files with 24 additions and 3 deletions

View File

@ -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):
"""
@ -65,3 +69,16 @@ class BaseModel(object):
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

View File

@ -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):
"""