Commits

Wojciech Walczak  committed 0390106

Fix lack of db reloading problem

  • Participants
  • Parent commits a121122

Comments (0)

Files changed (2)

File sphinx/web/dbutils.py

 """
 
 import cPickle
+from os import path
 from sphinx.errors import SphinxError
 
 class PickleLoadSave(object):
 
 class RepoSums(PickleLoadSave):
     def __init__(self, sumsfile):
-        self.sumsfile = sumsfile
+        self.dbfile = sumsfile
 
     def add_record(self, filename, md5sum):
-        data = self.dbread(self.sumsfile)
+        data = self.dbread(self.dbfile)
         data[filename] = md5sum
-        self.dbsave(self.sumsfile, data)
+        self.dbsave(self.dbfile, data)
 
     def get_record(self, filename):
-        data = self.dbread(self.sumsfile)
+        data = self.dbread(self.dbfile)
         return data.get(filename)
 
     def sum_changed(self, filename, md5sum):
         In any of above cases - add a new pair to the database.
 
         Return False otherwise (e.g. the pairs are the same)."""
-        data = self.dbread(self.sumsfile)
+        data = self.dbread(self.dbfile)
         if not data:
             self.add_record(filename, md5sum)
             return True
     def __init__(self, dbfile):
         self.dbfile = dbfile
         self.data = self.dbread(self.dbfile)
+        self.mtime = path.exists(dbfile) and path.getmtime(self.dbfile) or 0
 
     def add_record(self, filename, pid, paragraph, save=False):
         """Add a record to the database. 'filename' is key
         if save:
             self.dbsave(self.dbfile, self.data)
 
-    def get_paragraph(self, filename, pid):
+    def get_paragraph(self, filename, pid, dbreload=False):
+        if dbreload:
+            mtime = path.exists(self.dbfile) and path.getmtime(self.dbfile)
+            if mtime != self.mtime:
+                self.data = self.dbread(self.dbfile)
+                self.mtime = mtime
         if filename in self.data and pid in self.data[filename]:
             return self.data[filename][pid]
         return None

File sphinx/web/middleware/appserver.py

         node = req.GET['node']
         pid = req.GET['id']
         resp.status = 200
-        resp.body = json.dumps(self.piddb.get_paragraph(node, pid))
+        resp.body = json.dumps(self.piddb.get_paragraph(node, pid, dbreload=True))
         return resp
 
     def doHTMLFile(self, req, resp):