optimizations

This commit is contained in:
Anand Doshi 2015-03-18 15:05:25 +05:30
parent 2115ee3e71
commit b2d7efa682
9 changed files with 35 additions and 17 deletions

View file

@ -107,6 +107,7 @@ def init(site, sites_path=None):
local.user = None
local.role_permissions = {}
local.valid_columns = {}
local.jenv = None
local.jloader =None

View file

@ -30,7 +30,8 @@ def pass_context(f):
if profile:
pr.disable()
s = StringIO.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('tottime', 'ncalls')
ps = pstats.Stats(pr, stream=s)\
.sort_stats('cumtime', 'tottime', 'ncalls')
ps.print_stats()
print s.getvalue()
@ -72,8 +73,12 @@ def _new_site(db_name, site, mariadb_root_username=None, mariadb_root_password=N
import frappe.utils.scheduler
frappe.init(site=site)
# enable scheduler post install?
enable_scheduler = _is_scheduler_enabled()
try:
# enable scheduler post install?
enable_scheduler = _is_scheduler_enabled()
except:
enable_scheduler = False
install_db(root_login=mariadb_root_username, root_password=mariadb_root_password, db_name=db_name, admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
make_site_dirs()
@ -132,7 +137,7 @@ def reinstall(context):
frappe.clear_cache()
installed = frappe.get_installed_apps()
frappe.clear_cache()
except:
except Exception, e:
installed = []
raise
finally:

View file

@ -247,6 +247,8 @@ class Database:
def convert_to_simple_type(self, v, formatted=0):
"""Format date, time, longint values."""
return v
from frappe.utils import formatdate, fmt_money
if isinstance(v, (datetime.date, datetime.timedelta, datetime.datetime, long)):

View file

@ -9,4 +9,5 @@ from frappe.model.document import Document
class Currency(Document):
def validate(self):
frappe.clear_cache()
if not frappe.flags.in_install_app:
frappe.clear_cache()

View file

@ -88,6 +88,7 @@ def make_connection(root_login, root_password):
return frappe.database.Database(user=root_login, password=root_password)
def install_app(name, verbose=False, set_as_patched=True):
frappe.clear_cache()
app_hooks = frappe.get_hooks(app_name=name)
installed_apps = frappe.get_installed_apps()

View file

@ -179,16 +179,22 @@ class BaseDocument(object):
if key not in self.__dict__:
self.__dict__[key] = None
if self.doctype in ("DocField", "DocPerm") and self.parent in ("DocType", "DocField", "DocPerm"):
from frappe.model.meta import get_table_columns
valid = get_table_columns(self.doctype)
else:
valid = self.meta.get_valid_columns()
for key in valid:
for key in self.get_valid_columns():
if key not in self.__dict__:
self.__dict__[key] = None
def get_valid_columns(self):
if self.doctype not in frappe.local.valid_columns:
if self.doctype in ("DocField", "DocPerm") and self.parent in ("DocType", "DocField", "DocPerm"):
from frappe.model.meta import get_table_columns
valid = get_table_columns(self.doctype)
else:
valid = self.meta.get_valid_columns()
frappe.local.valid_columns[self.doctype] = valid
return frappe.local.valid_columns[self.doctype]
def is_new(self):
return self.get("__islocal")

View file

@ -124,6 +124,7 @@ class Meta(Document):
self.add_custom_fields()
self.apply_property_setters()
self.sort_fields()
self.get_valid_columns()
def add_custom_fields(self):
try:

View file

@ -107,7 +107,7 @@ def add_country_and_currency(name, country):
"code": country.code,
"date_format": country.date_format or "dd-mm-yyyy",
"time_zones": "\n".join(country.timezones or [])
}).insert()
}).db_insert()
if country.currency and not frappe.db.exists("Currency", country.currency):
frappe.get_doc({
@ -117,5 +117,5 @@ def add_country_and_currency(name, country):
"symbol": country.currency_symbol,
"fraction_units": country.currency_fraction_units,
"number_format": country.number_format
}).insert()
}).db_insert()

View file

@ -35,9 +35,9 @@ class RedisWrapper(redis.Redis):
:param generator: Function to be called to generate a value if `None` is returned."""
original_key = key
key = self.make_key(key, user)
val = frappe.local.cache.get(key)
if val is None:
if key not in frappe.local.cache:
val = None
if not frappe.local.flags.in_install:
try:
val = self.get(key)
@ -50,7 +50,8 @@ class RedisWrapper(redis.Redis):
self.set_value(original_key, val, user=user)
else:
frappe.local.cache[key] = val
return val
return frappe.local.cache.get(key)
def get_all(self, key):
ret = {}