cb_filestat patch
Ryan Barrett <pyblosxom-6sb6M7qyT/[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
hi again. i'm attaching a proposed patch to tools.filestat that changes the way the cb_filestat callback is handled. currently, cb_filestat is intended to let plugins override the mtime returned from os.stat(). however, those plugins are often also in the position to provide a cheaper alternative to os.stat() altogether. hardcodedates is a good example; it stores all mtimes in a single file. in the case of large pyblosxom sites, reading that file once is *much* faster and cheaper than statting hundreds, possibly thousands of separate entry files. this patch changes tools.filestat to let plugins provide a stat value first. it only falls back to os.stat() if no plugin provides a value. -Ryan -- http://snarfed.org/ ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Pyblosxom-devel mailing list Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
pyblosxom_filestat.patch
(text/plain, 3.3 KB)
Index: Pyblosxom/tools.py
===================================================================
*** Pyblosxom/tools.py (revision 835)
--- Pyblosxom/tools.py (working copy)
***************
*** 389,400 ****
return filestat_cache[filename]
argdict = {"request": request, "filename": filename,
! "mtime": os.stat(filename)}
argdict = run_callback("filestat",
argdict,
mappingfunc=lambda x,y:y,
! defaultfunc=lambda x:x)
! timetuple = time.localtime(argdict["mtime"][8])
filestat_cache[filename] = timetuple
return timetuple
--- 389,406 ----
return filestat_cache[filename]
argdict = {"request": request, "filename": filename,
! "mtime": [0] * 10}
argdict = run_callback("filestat",
argdict,
mappingfunc=lambda x,y:y,
! donefunc=lambda x: x['mtime'][8] != 0,
! defaultfunc=lambda x:x)
!
! # no plugin handled cb_filestat; default to asking the os.
! if argdict['mtime'][8] == 0:
! argdict['mtime'] = os.stat(filename)
!
! timetuple = time.localtime(argdict["mtime"][8])
filestat_cache[filename] = timetuple
return timetuple
Index: docs/chapter_architecture.docbook
===================================================================
*** docs/chapter_architecture.docbook (revision 835)
--- docs/chapter_architecture.docbook (working copy)
***************
*** 455,463 ****
<sect2>
<title>cb_filestat</title>
<para>
! The filestat callback allows plugins to override the mtime of
! the entry. One of the contributed plugins uses this to set the
! mtime to the time specified in the entry's filename.
</para>
<para>
Functions that implement this callback will get an args dict containing:
--- 455,469 ----
<sect2>
<title>cb_filestat</title>
<para>
! The filestat callback allows plugins to provide mtimes for entries. Plugins
! may use this to override the mtime stored in the filesystem. For exaample, one
! of the contributed plugins uses this to set the mtime to the time specified in
! the entry's filename.
!
! Plugins may also use this to provide a cheaper alternative to filesystem stat
! calls, a notorious performance drag, The hardcodedates plugin, for example,
! stores mtimes in a file. It reads the file once at startup, then returns
! mtimes from its in-memory database.
</para>
<para>
Functions that implement this callback will get an args dict containing:
***************
*** 468,475 ****
entry</para></listitem>
</itemizedlist>
<para>
! Functions that implement this callback must return the input args
! dict whether or not they adjust anything in it.
</para>
</sect2>
--- 474,483 ----
entry</para></listitem>
</itemizedlist>
<para>
! Functions that implement this callback must return the input args dict whether
! or not they adjust anything in it. The callback chain will stop as soon as a
! callback modifies mtime. If no plugin handles the callback, pyblosxom will
! fall back to calling os.stat().
</para>
</sect2>