Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
Now os.stat()'s on load rather than on scan. Substantially improves f…
Browse files Browse the repository at this point in the history
…irst load speed.
  • Loading branch information
Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) committed Mar 5, 2012
1 parent 574d66b commit 418f4d8
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions BEXML/libBEXML/parsers/be_dir.py
Expand Up @@ -24,7 +24,7 @@ def __init__(self, parentIssue, dirpath, encoding):
self.__loaded=True self.__loaded=True
self.uuid=os.path.basename(dirpath) self.uuid=os.path.basename(dirpath)
self.__loaded=False self.__loaded=False
self.__refreshStat() self.stat=None


@property @property
def isLoaded(self): def isLoaded(self):
Expand All @@ -41,17 +41,12 @@ def __getStat(self):
stat.body=os.stat(os.path.join(self.dirpath, "body")) stat.body=os.stat(os.path.join(self.dirpath, "body"))
return stat return stat


def __refreshStat(self):
"""Reloads the stats for the file backing of this comment"""
self.stat=self.__getStat()

@property @property
def isStale(self): def isStale(self):
"""True if the file backing for this comment is newer than us""" """True if the file backing for this comment is newer than us"""
stat=self.__getStat()
if not self.__loaded: if not self.__loaded:
self.stat=stat return None
return False stat=self.__getStat()
return stat.values!=self.stat.values return stat.values!=self.stat.values


def load(self, reload=False): def load(self, reload=False):
Expand All @@ -68,7 +63,7 @@ def load(self, reload=False):
log.warn("The following values from comment '"+self.dirpath+"' were not recognised: "+repr(notloaded)) log.warn("The following values from comment '"+self.dirpath+"' were not recognised: "+repr(notloaded))
self.__loaded=True self.__loaded=True
self._dirty=False self._dirty=False
stat=self.__getStat() self.stat=self.__getStat()


def __getitem__(self, name): def __getitem__(self, name):
if self._isProperty(name) and not self.isLoaded: if self._isProperty(name) and not self.isLoaded:
Expand Down Expand Up @@ -107,7 +102,7 @@ def __init__(self, dirpath, encoding):
self.__loaded=True self.__loaded=True
self.uuid=os.path.basename(dirpath) self.uuid=os.path.basename(dirpath)
self.__loaded=False self.__loaded=False
self.__refreshStat() self.stat=None


@property @property
def isLoaded(self): def isLoaded(self):
Expand All @@ -120,17 +115,12 @@ def __getStat(self):
stat.values=os.stat(os.path.join(self.dirpath, "values")) stat.values=os.stat(os.path.join(self.dirpath, "values"))
return stat return stat


def __refreshStat(self):
"""Reloads the stats for the file backing of this issue"""
self.stat=self.__getStat()

@property @property
def isStale(self): def isStale(self):
"""True if the file backing for this issue is newer than us""" """True if the file backing for this issue is newer than us"""
stat=self.__getStat()
if not self.__loaded: if not self.__loaded:
self.stat=stat return None
return False stat=self.__getStat()
return stat.values!=self.stat.values return stat.values!=self.stat.values


def addComment(self, dirpath): def addComment(self, dirpath):
Expand Down Expand Up @@ -165,7 +155,7 @@ def load(self, reload=False):
log.warn("The following values from issue '"+self.dirpath+"' were not recognised: "+repr(notloaded)) log.warn("The following values from issue '"+self.dirpath+"' were not recognised: "+repr(notloaded))
self.__loaded=True self.__loaded=True
self._dirty=False self._dirty=False
stat=self.__getStat() self.stat=self.__getStat()


def __getitem__(self, name): def __getitem__(self, name):
if self._isProperty(name) and not self.isLoaded: if self._isProperty(name) and not self.isLoaded:
Expand Down Expand Up @@ -203,7 +193,7 @@ def __init__(self, uri, encoding="UTF-8", cache_in_memory=True):
ParserBase.__init__(self, uri) ParserBase.__init__(self, uri)
self.version="" # This repo's version string self.version="" # This repo's version string
self.encoding=encoding # How to treat text files in this repo self.encoding=encoding # How to treat text files in this repo
self.__bedir={} # Dictionary of bug directories in repo self.__bedir={} # Dictionary of bug directories in repo
if not cache_in_memory: if not cache_in_memory:
log.warn("cache_in_memory=False not supported and therefore ignored") log.warn("cache_in_memory=False not supported and therefore ignored")


Expand Down

0 comments on commit 418f4d8

Please sign in to comment.