[MERGE] forward port of branch saas-1 up to revid 4893 chs@openerp.com-20130701153735-xnbb8zauabf1k63u

bzr revid: chs@openerp.com-20130702144745-763n9cdphkppshxl
This commit is contained in:
Christophe Simonis 2013-07-02 16:47:45 +02:00
commit 5a58a48ef5
4 changed files with 28 additions and 11 deletions

View File

@ -1067,6 +1067,8 @@ class function(_column):
self._classic_write = True self._classic_write = True
if type=='binary': if type=='binary':
self._symbol_get=lambda x:x and str(x) self._symbol_get=lambda x:x and str(x)
else:
self._prefetch = True
if type == 'float': if type == 'float':
self._symbol_c = float._symbol_c self._symbol_c = float._symbol_c

View File

@ -385,11 +385,11 @@ class browse_record(object):
# if the field is a classic one or a many2one, we'll fetch all classic and many2one fields # if the field is a classic one or a many2one, we'll fetch all classic and many2one fields
if col._prefetch: if col._prefetch:
# gen the list of "local" (ie not inherited) fields which are classic or many2one # gen the list of "local" (ie not inherited) fields which are classic or many2one
fields_to_fetch = filter(lambda x: x[1]._classic_write, self._table._columns.items()) fields_to_fetch = filter(lambda x: x[1]._classic_write and x[1]._prefetch, self._table._columns.items())
# gen the list of inherited fields # gen the list of inherited fields
inherits = map(lambda x: (x[0], x[1][2]), self._table._inherit_fields.items()) inherits = map(lambda x: (x[0], x[1][2]), self._table._inherit_fields.items())
# complete the field list with the inherited fields which are classic or many2one # complete the field list with the inherited fields which are classic or many2one
fields_to_fetch += filter(lambda x: x[1]._classic_write, inherits) fields_to_fetch += filter(lambda x: x[1]._classic_write and x[1]._prefetch, inherits)
# otherwise we fetch only that field # otherwise we fetch only that field
else: else:
fields_to_fetch = [(name, col)] fields_to_fetch = [(name, col)]
@ -1034,6 +1034,7 @@ class BaseModel(object):
'ondelete': field['on_delete'], 'ondelete': field['on_delete'],
'translate': (field['translate']), 'translate': (field['translate']),
'manual': True, 'manual': True,
'_prefetch': False,
#'select': int(field['select_level']) #'select': int(field['select_level'])
} }

View File

@ -116,10 +116,13 @@ def _process_text(self, txt):
result += tools.ustr(self.localcontext.get('translate', lambda x:x)(to_translate)) result += tools.ustr(self.localcontext.get('translate', lambda x:x)(to_translate))
if sps: if sps:
txt = None txt = None
expr = sps.pop(0) try:
txt = eval(expr, self.localcontext) expr = sps.pop(0)
if txt and isinstance(txt, basestring): txt = eval(expr, self.localcontext)
txt = tools.ustr(txt) if txt and isinstance(txt, basestring):
txt = tools.ustr(txt)
except Exception:
_logger.error("Failed to evaluate expression [[ %s ]] with context %r while rendering report, ignored.", expr, self.localcontext)
if isinstance(txt, basestring): if isinstance(txt, basestring):
result += txt result += txt
elif txt and (txt is not None) and (txt is not False): elif txt and (txt is not None) and (txt is not False):

View File

@ -196,7 +196,7 @@ class Multicorn(object):
def stop(self, graceful=True): def stop(self, graceful=True):
if self.long_polling_pid is not None: if self.long_polling_pid is not None:
self.worker_kill(self.long_polling_pid, signal.SIGTERM) self.worker_kill(self.long_polling_pid, signal.SIGKILL) # FIXME make longpolling process handle SIGTERM correctly
self.long_polling_pid = None self.long_polling_pid = None
if graceful: if graceful:
_logger.info("Stopping gracefully") _logger.info("Stopping gracefully")
@ -392,14 +392,18 @@ class WorkerCron(Worker):
interval = 60 + self.pid % 10 # chorus effect interval = 60 + self.pid % 10 # chorus effect
time.sleep(interval) time.sleep(interval)
def process_work(self): def _db_list(self):
rpc_request = logging.getLogger('openerp.netsvc.rpc.request')
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
_logger.debug("WorkerCron (%s) polling for jobs", self.pid)
if config['db_name']: if config['db_name']:
db_names = config['db_name'].split(',') db_names = config['db_name'].split(',')
else: else:
db_names = openerp.service.db.exp_list(True) db_names = openerp.service.db.exp_list(True)
return db_names
def process_work(self):
rpc_request = logging.getLogger('openerp.netsvc.rpc.request')
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
_logger.debug("WorkerCron (%s) polling for jobs", self.pid)
db_names = self._db_list()
if len(db_names): if len(db_names):
self.db_index = (self.db_index + 1) % len(db_names) self.db_index = (self.db_index + 1) % len(db_names)
db_name = db_names[self.db_index] db_name = db_names[self.db_index]
@ -433,8 +437,15 @@ class WorkerCron(Worker):
self.db_index = 0 self.db_index = 0
def start(self): def start(self):
os.nice(10) # mommy always told me to be nice with others...
Worker.start(self) Worker.start(self)
self.multi.socket.close() self.multi.socket.close()
openerp.service.start_internal() openerp.service.start_internal()
# chorus effect: make cron workers do not all start at first database
mct = config['max_cron_threads']
p = float(self.pid % mct) / mct
self.db_index = int(len(self._db_list()) * p)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: