8377: cache path
This commit is contained in:
parent
12e9764fdd
commit
4fcdd8c4a6
@ -34,11 +34,13 @@ class BaseModel(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lru_data = LRU(BaseModel._CACHE_SIZE)
|
self.lru_data = LRU(BaseModel._CACHE_SIZE)
|
||||||
|
self.lru_path = LRU(BaseModel._CACHE_SIZE)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
self.lru_data = None
|
self.lru_data = None
|
||||||
|
self.lru_path = None
|
||||||
|
|
||||||
def clear_cache(self, handle=None):
|
def clear_cache(self, handle=None):
|
||||||
"""
|
"""
|
||||||
@ -49,6 +51,8 @@ class BaseModel(object):
|
|||||||
del self.lru_data[handle]
|
del self.lru_data[handle]
|
||||||
else:
|
else:
|
||||||
self.lru_data.clear()
|
self.lru_data.clear()
|
||||||
|
# Invalidates all paths
|
||||||
|
self.lru_path.clear()
|
||||||
|
|
||||||
def get_cached_value(self, handle, col):
|
def get_cached_value(self, handle, col):
|
||||||
"""
|
"""
|
||||||
@ -65,3 +69,16 @@ class BaseModel(object):
|
|||||||
self.lru_data[handle] = {}
|
self.lru_data[handle] = {}
|
||||||
self.lru_data[handle][col] = data
|
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
|
||||||
|
@ -966,6 +966,9 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
|
|||||||
"""
|
"""
|
||||||
Returns a path from a given node.
|
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)
|
node = self.get_node_from_iter(iter)
|
||||||
pathlist = []
|
pathlist = []
|
||||||
while node.parent is not None:
|
while node.parent is not None:
|
||||||
@ -978,12 +981,13 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
|
|||||||
index += 1
|
index += 1
|
||||||
pathlist.append(index)
|
pathlist.append(index)
|
||||||
node = parent
|
node = parent
|
||||||
|
|
||||||
if pathlist:
|
if pathlist:
|
||||||
pathlist.reverse()
|
pathlist.reverse()
|
||||||
return Gtk.TreePath(tuple(pathlist))
|
retval = Gtk.TreePath(tuple(pathlist))
|
||||||
else:
|
else:
|
||||||
return None
|
retval = None
|
||||||
|
self.set_cached_path(iter.user_data, retval)
|
||||||
|
return retval
|
||||||
|
|
||||||
def do_iter_next(self, iter):
|
def do_iter_next(self, iter):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user