many speed improvements, thanks Michele

This commit is contained in:
mdipierro
2012-08-28 08:28:36 -05:00
parent 37f81b48e8
commit 18a2c2c68e
4 changed files with 19 additions and 30 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.1 (2012-08-27 16:16:20) rc4 Version 2.00.1 (2012-08-28 08:28:31) rc4
+10 -23
View File
@@ -160,12 +160,8 @@ def LOAD(c=None, f='index', args=None, vars=None,
if not isinstance(args,(list,tuple)): if not isinstance(args,(list,tuple)):
args = [args] args = [args]
c = c or request.controller c = c or request.controller
other_request = Storage() other_request = Storage(request)
for key, value in request.items(): other_request['env'] = Storage(request.env)
other_request[key] = value
other_request['env'] = Storage()
for key, value in request.env.items():
other_request.env[key] = value
other_request.controller = c other_request.controller = c
other_request.function = f other_request.function = f
other_request.extension = extension or request.extension other_request.extension = extension or request.extension
@@ -200,8 +196,7 @@ def LOAD(c=None, f='index', args=None, vars=None,
page = run_controller_in(c, f, other_environment) page = run_controller_in(c, f, other_environment)
if isinstance(page, dict): if isinstance(page, dict):
other_response._vars = page other_response._vars = page
for key in page: other_response._view_environment.update(page)
other_response._view_environment[key] = page[key]
run_view_in(other_response._view_environment) run_view_in(other_response._view_environment)
page = other_response.body.getvalue() page = other_response.body.getvalue()
current.request, current.response = original_request, original_response current.request, current.response = original_request, original_response
@@ -245,12 +240,8 @@ class LoadFactory(object):
args = [args] args = [args]
c = c or request.controller c = c or request.controller
other_request = Storage() other_request = Storage(request)
for key, value in request.items(): other_request['env'] = Storage(request.env)
other_request[key] = value
other_request['env'] = Storage()
for key, value in request.env.items():
other_request.env['key'] = value
other_request.controller = c other_request.controller = c
other_request.function = f other_request.function = f
other_request.extension = extension or request.extension other_request.extension = extension or request.extension
@@ -283,8 +274,7 @@ class LoadFactory(object):
page = run_controller_in(c, f, other_environment) page = run_controller_in(c, f, other_environment)
if isinstance(page, dict): if isinstance(page, dict):
other_response._vars = page other_response._vars = page
for key in page: other_response._view_environment.update(page)
other_response._view_environment[key] = page[key]
run_view_in(other_response._view_environment) run_view_in(other_response._view_environment)
page = other_response.body.getvalue() page = other_response.body.getvalue()
current.request, current.response = original_request, original_response current.request, current.response = original_request, original_response
@@ -358,12 +348,9 @@ def build_environment(request, response, session, store_current=True):
""" """
Build the environment dictionary into which web2py files are executed. Build the environment dictionary into which web2py files are executed.
""" """
h,v = html,validators
environment = {} environment = dict((k,getattr(h,k)) for k in h.__all__)
for key in html.__all__: environment.update((k,getattr(v, k)) for k in v.__all__)
environment[key] = getattr(html, key)
for key in validators.__all__:
environment[key] = getattr(validators, key)
if not request.env: if not request.env:
request.env = Storage() request.env = Storage()
@@ -592,7 +579,7 @@ def run_view_in(environment):
path = os.path.join(folder, 'compiled') path = os.path.join(folder, 'compiled')
badv = 'invalid view (%s)' % response.view badv = 'invalid view (%s)' % response.view
patterns = response.generic_patterns or [] patterns = response.generic_patterns or []
regex = re.compile('|'.join(fnmatch.translate(r) for r in patterns)) regex = re.compile('|'.join(map(fnmatch.translate, patterns)))
short_action = '%(controller)s/%(function)s.%(extension)s' % request short_action = '%(controller)s/%(function)s.%(extension)s' % request
allow_generic = patterns and regex.search(short_action) allow_generic = patterns and regex.search(short_action)
if not isinstance(response.view, str): if not isinstance(response.view, str):
+7 -4
View File
@@ -6309,6 +6309,7 @@ class Row(object):
a dictionary that lets you do d['a'] as well as d.a a dictionary that lets you do d['a'] as well as d.a
this is only used to store a Row this is only used to store a Row
""" """
def __init__(self,*args,**kwargs): def __init__(self,*args,**kwargs):
self.__dict__.update(*args,**kwargs) self.__dict__.update(*args,**kwargs)
@@ -6537,7 +6538,7 @@ class DAL(object):
db.define_table('tablename', Field('fieldname1'), db.define_table('tablename', Field('fieldname1'),
Field('fieldname2')) Field('fieldname2'))
""" """
@staticmethod @staticmethod
def set_folder(folder): def set_folder(folder):
""" """
@@ -7257,7 +7258,7 @@ class Table(object):
db.users.insert(name='me') # print db.users._insert(...) to see SQL db.users.insert(name='me') # print db.users._insert(...) to see SQL
db.users.drop() db.users.drop()
""" """
def __init__( def __init__(
self, self,
db, db,
@@ -8546,9 +8547,11 @@ class Set(object):
tablename = self.db._adapter.get_table(self.query) tablename = self.db._adapter.get_table(self.query)
table = self.db[tablename] table = self.db[tablename]
table._attempt_upload(update_fields) table._attempt_upload(update_fields)
if any(f(self,update_fields) for f in table._before_update): return 0 if any(f(self,update_fields) for f in table._before_update):
return 0
fields = table._listify(update_fields,update=True) fields = table._listify(update_fields,update=True)
if not fields: raise SyntaxError, "No fields to update" if not fields:
raise SyntaxError, "No fields to update"
ret = self.db._adapter.update(tablename,self.query,fields) ret = self.db._adapter.update(tablename,self.query,fields)
ret and [f(self,update_fields) for f in table._after_update] ret and [f(self,update_fields) for f in table._after_update]
return ret return ret
+1 -2
View File
@@ -209,8 +209,7 @@ def serve_controller(request, response, session):
page = run_controller_in(request.controller, request.function, environment) page = run_controller_in(request.controller, request.function, environment)
if isinstance(page, dict): if isinstance(page, dict):
response._vars = page response._vars = page
for key in page: response._view_environment.update(page)
response._view_environment[key] = page[key]
run_view_in(response._view_environment) run_view_in(response._view_environment)
page = response.body.getvalue() page = response.body.getvalue()
# logic to garbage collect after exec, not always, once every 100 requests # logic to garbage collect after exec, not always, once every 100 requests