Commits

ben...@localhost.metavers.net  committed a8a0417

merge.

  • Participants
  • Parent commits e33e81e

Comments (0)

Files changed (4)

File friendpaste.fcgi

-#!/usr/bin/python
+#!/usr/local/bin/python
 # -*- coding: utf-8 -*-
 
 # Copyright 2008 by Benoît Chesneau <benoit@amisphere.org>

File friendpaste/application.py

 from jinja import Environment
 from couchdb import Server, ServerError
 
+
 from friendpaste import settings
 from friendpaste.urls import map, all_views
 from friendpaste.utils import local, local_manager
             db = couchdb_server[settings.DATABASE_NAME]
 
         init_views(db)
+
         self.initialized = True
 
     def bind_to_thread(self):

File friendpaste/dbsession.py

 
     # TODO: better handling of conection lost 
     def _get_db(self):
+
         try:
             couchdb_server = Server(self.uri)
         except:
                 raise NotFound
         return couchdb_server[self.dbname]
     db = property(_get_db)
-        
+
 class ScopedCouchDBSession(object):
     def __init__(self, session_factory, scopefunc=None):
         self.session_factory = session_factory

File friendpaste/paste/views.py

 # limitations under the License.
 
 import os.path
+import time
 
 from wtforms import Form, TextField, TextAreaField, SelectField, ValidationError, \
         validators
     return resp
 
 def _get_snippet_revisions(id):
-    #db = local.application.db
-    # we get only last 10 revisions
-    #res = db.view('_view/paste/by_id', startkey=[str(id)], endkey=[str(id),10]) 
-    res = couchdb_proxy.view('_view/paste/by_id', startkey=[str(id)], endkey=[str(id),10])
+    
+    def _fetch():
+        r = couchdb_proxy.view('_view/paste/by_id', startkey=[str(id)], endkey=[str(id),10])
+        return r, len(r)
+    
+    nb_try = 0
+    while 1:
+        res, l = _fetch()
+        if l > 0:
+            break
+        time.sleep(0.1)
+        if nb_try == 1:
+            break
+        nb_try += 1
+
+    if l == 0:
+        raise NotFound
     results = []
     for r in res.__iter__():
         results.append(r)