# HG changeset patch # User Steve Losh # Date 1276458882 14400 # Node ID d56ad4bf9dd5373875c53014c8c7db3ef02cc07a # Parent 13b6260aed9982718503da2b9b6cf5e182eb35ee web: reload the data store on each request This kind of sucks, but it is the best we can do at the moment. diff -r 13b6260aed99 -r d56ad4bf9dd5 contrib/deploy/wsgi.py --- a/contrib/deploy/wsgi.py Sun Jun 13 15:40:19 2010 -0400 +++ b/contrib/deploy/wsgi.py Sun Jun 13 15:54:42 2010 -0400 @@ -15,7 +15,6 @@ from mercurial import hg, ui from web_ui import app -from api import ReviewDatastore _ui = ui.ui() _ui.setconfig('ui', 'user', ANON_USER) @@ -26,6 +25,7 @@ app.site_root = SITE_ROOT.rstrip('/') app.title = TITLE app.debug = False -app.datastore = ReviewDatastore(_ui, repo) +app.ui = _ui +app.repo = repo application = app diff -r 13b6260aed99 -r d56ad4bf9dd5 review/web_ui.py --- a/review/web_ui.py Sun Jun 13 15:40:19 2010 -0400 +++ b/review/web_ui.py Sun Jun 13 15:54:42 2010 -0400 @@ -5,7 +5,7 @@ import sys, os from hashlib import md5 -from mercurial import commands, templatefilters +from mercurial import commands, hg, templatefilters from mercurial.node import short from mercurial.util import email @@ -30,7 +30,7 @@ unbundle() from flask import Flask -from flask import abort, redirect, render_template, request +from flask import abort, g, redirect, render_template, request app = Flask(__name__) LOG_PAGE_LEN = 15 @@ -65,17 +65,21 @@ def _render(template, **kwargs): return render_template(template, read_only=app.read_only, - allow_anon=app.allow_anon, utils=utils, datastore=app.datastore, + allow_anon=app.allow_anon, utils=utils, datastore=g.datastore, title=app.title, **kwargs) +@app.before_request +def load_datastore(): + g.datastore = api.ReviewDatastore(app.ui, hg.repository(app.ui, app.repo.root)) + @app.route('/') def index_newest(): return index(-1) @app.route('//') def index(rev_max): - tip = app.datastore.target['tip'].rev() + tip = g.datastore.target['tip'].rev() if rev_max > tip or rev_max < 0: rev_max = tip @@ -89,7 +93,7 @@ if newer > tip: newer = tip - rcsets = [app.datastore[r] for r in xrange(rev_max, rev_min - 1, -1)] + rcsets = [g.datastore[r] for r in xrange(rev_max, rev_min - 1, -1)] return _render('index.html', rcsets=rcsets, newer=newer, older=older) @@ -103,7 +107,7 @@ signoff = '' body = request.form.get('new-signoff-body', '') - rcset = app.datastore[revhash] + rcset = g.datastore[revhash] rcset.add_signoff(body, signoff, force=True) return redirect("%s/changeset/%s/" % (app.site_root, revhash)) @@ -116,7 +120,7 @@ body = request.form['new-comment-body'] if body: - rcset = app.datastore[revhash] + rcset = g.datastore[revhash] rcset.add_comment(body, filename, lines) return redirect("%s/changeset/%s/" % (app.site_root, revhash)) @@ -130,7 +134,7 @@ elif not app.read_only or app.allow_anon: return _handle_comment(revhash) - rcset = app.datastore[revhash] + rcset = g.datastore[revhash] rev = rcset.target[revhash] cu_signoffs = rcset.signoffs_for_current_user() @@ -145,14 +149,14 @@ def pull(): if not app.read_only: path = request.form['path'] - commands.pull(app.datastore.repo.ui, app.datastore.repo, path, update=True) + commands.pull(g.datastore.repo.ui, g.datastore.repo, path, update=True) return redirect('%s/' % app.site_root) @app.route('/push/', methods=['POST']) def push(): if not app.read_only: path = request.form['path'] - commands.push(app.datastore.repo.ui, app.datastore.repo, path) + commands.push(g.datastore.repo.ui, g.datastore.repo, path) return redirect('%s/' % app.site_root) @@ -170,7 +174,8 @@ if app.allow_anon: ui.setconfig('ui', 'username', 'Anonymous ') - app.datastore = api.ReviewDatastore(ui, repo) + app.ui = ui + app.repo = repo app.title = os.path.basename(repo.root) if app.debug: