[IMP] calendar: simplify/optimize `rrule` computed field
Avoid reading one record at a time, leading to multiple calls to read() which is special-cased and even slower than a normal one.
This commit is contained in:
parent
d837d4b497
commit
30ddb67299
|
@ -776,21 +776,17 @@ class calendar_event(osv.Model):
|
||||||
if not isinstance(ids, list):
|
if not isinstance(ids, list):
|
||||||
ids = [ids]
|
ids = [ids]
|
||||||
|
|
||||||
for id in ids:
|
#read these fields as SUPERUSER because if the record is private a normal search could raise an error
|
||||||
#read these fields as SUPERUSER because if the record is private a normal search could return False and raise an error
|
events = self.read(cr, SUPERUSER_ID, ids,
|
||||||
data = self.browse(cr, SUPERUSER_ID, id, context=context)
|
['id', 'byday', 'recurrency', 'final_date', 'rrule_type', 'month_by',
|
||||||
|
'interval', 'count', 'end_type', 'mo', 'tu', 'we', 'th', 'fr', 'sa',
|
||||||
if data.interval and data.interval < 0:
|
'su', 'day', 'week_list'], context=context)
|
||||||
raise osv.except_osv(_('Warning!'), _('Interval cannot be negative.'))
|
for event in events:
|
||||||
if data.count and data.count <= 0:
|
if event['recurrency']:
|
||||||
raise osv.except_osv(_('Warning!'), _('Count cannot be negative or 0.'))
|
result[event['id']] = self.compute_rule_string(event)
|
||||||
|
|
||||||
data = self.read(cr, uid, id, ['id', 'byday', 'recurrency', 'final_date', 'rrule_type', 'month_by', 'interval', 'count', 'end_type', 'mo', 'tu', 'we', 'th', 'fr', 'sa', 'su', 'day', 'week_list'], context=context)
|
|
||||||
event = data['id']
|
|
||||||
if data['recurrency']:
|
|
||||||
result[event] = self.compute_rule_string(data)
|
|
||||||
else:
|
else:
|
||||||
result[event] = ""
|
result[event['id']] = ''
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# retro compatibility function
|
# retro compatibility function
|
||||||
|
@ -1180,6 +1176,11 @@ class calendar_event(osv.Model):
|
||||||
@param data: dictionary of freq and interval value
|
@param data: dictionary of freq and interval value
|
||||||
@return: string containing recurring rule (empty if no rule)
|
@return: string containing recurring rule (empty if no rule)
|
||||||
"""
|
"""
|
||||||
|
if data['interval'] and data['interval'] < 0:
|
||||||
|
raise osv.except_osv(_('warning!'), _('interval cannot be negative.'))
|
||||||
|
if data['count'] and data['count'] <= 0:
|
||||||
|
raise osv.except_osv(_('warning!'), _('count cannot be negative or 0.'))
|
||||||
|
|
||||||
def get_week_string(freq, data):
|
def get_week_string(freq, data):
|
||||||
weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
|
weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
|
||||||
if freq == 'weekly':
|
if freq == 'weekly':
|
||||||
|
|
Loading…
Reference in New Issue