[PERF]Radicale Odoo Storage : huge performance optimization caching all partners data and tags
This commit is contained in:
parent
39368e38fe
commit
15cf112cc3
@ -139,8 +139,17 @@ class Collection(BaseCollection):
|
||||
def get_contacts_from_odoo(cls, login):
|
||||
""" Gets all contacts available from one Odoo login """
|
||||
cls.logger.info('Get contacts for Odoo user %s' % login)
|
||||
partner_ids = cls.odoo.env['res.partner'].search([])
|
||||
return ['res.partner:%s' % pid for pid in partner_ids]
|
||||
fields = ['name', 'write_date', 'comment', 'street', 'street2', 'zip',
|
||||
'city', 'phone', 'mobile', 'fax', 'email', 'website',
|
||||
'function', 'comment', 'image',
|
||||
'category_id', 'parent_id', 'state_id', 'country_id']
|
||||
partners = cls.odoo.execute_kw('res.partner', 'search_read', [[]],
|
||||
{'fields': fields})
|
||||
cls.partners = {p['id']: p for p in partners}
|
||||
categs = cls.odoo.execute_kw('res.partner.category', 'search_read', [[]],
|
||||
{'fields': ['name']})
|
||||
cls.categs = {c['id']: c['name'] for c in categs}
|
||||
return ['res.partner:%s' % pid for pid in cls.partners.keys()]
|
||||
|
||||
@classmethod
|
||||
def get_events_from_odoo(cls, login, path):
|
||||
@ -182,49 +191,51 @@ class Collection(BaseCollection):
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def _generate_vcard_from_odoo(cls, partner):
|
||||
def _generate_vcard_from_odoo(cls, database_id):
|
||||
""" Generate and return vCard object from Odoo res.partner record """
|
||||
# last_modified = strftime("%a, %d %b %Y %H:%M:%S GMT",
|
||||
# strptime(data.get('write_date'), '%Y-%m-%d %H:%M:%S'))
|
||||
last_modified = str(partner.write_date)
|
||||
partner = cls.partners.get(database_id)
|
||||
last_modified = str(partner.get('write_date'))
|
||||
vobject_item = vobject.vCard()
|
||||
vobject_item.add('n')
|
||||
vobject_item.add('fn')
|
||||
vobject_item.fn.value = partner.name
|
||||
vobject_item.fn.value = partner.get('name')
|
||||
vobject_item.add('adr')
|
||||
state_name = partner.state_id.name if partner.state_id else ''
|
||||
country_name = partner.country_id.name if partner.country_id else ''
|
||||
state_name = partner.get('state_id')[1] if partner.get('state_id') else ''
|
||||
country_name = partner.get('country_id')[1] if partner.get('country_id') else ''
|
||||
vobject_item.adr.value = vobject.vcard.Address(
|
||||
street=' '.join([partner.street or '', partner.street2 or '']),
|
||||
code=partner.zip or '', city=partner.city or '',
|
||||
street=' '.join([partner.get('street') or '', partner.get('street2') or '']),
|
||||
code=partner.get('zip') or '', city=partner.get('city') or '',
|
||||
region=state_name, country=country_name)
|
||||
if partner.image:
|
||||
vobject_item.add('photo;encoding=b;type=jpeg').value = partner.image.replace('\n', '')
|
||||
if partner.phone:
|
||||
if partner.get('image'):
|
||||
vobject_item.add('photo;encoding=b;type=jpeg').value = partner.get(
|
||||
'image').replace('\n', '')
|
||||
if partner.get('phone'):
|
||||
tel = vobject_item.add('tel')
|
||||
tel.type_param = 'Tel'
|
||||
tel.value = partner.phone
|
||||
if partner.mobile:
|
||||
tel.value = partner.get('phone')
|
||||
if partner.get('mobile'):
|
||||
tel = vobject_item.add('tel')
|
||||
tel.type_param = 'Mobile'
|
||||
tel.value = partner.mobile
|
||||
if partner.fax:
|
||||
tel.value = partner.get('mobile')
|
||||
if partner.get('fax'):
|
||||
tel = vobject_item.add('tel')
|
||||
tel.type_param = 'Fax'
|
||||
tel.value = partner.fax
|
||||
if partner.email:
|
||||
vobject_item.add('email').value = partner.email
|
||||
if partner.website:
|
||||
vobject_item.add('url').value = partner.website
|
||||
if partner.function:
|
||||
vobject_item.add('role').value = partner.function
|
||||
if partner.comment:
|
||||
vobject_item.add('note').value = partner.comment
|
||||
if partner.category_id:
|
||||
categs = [categ.name for categ in partner.category_id]
|
||||
tel.value = partner.get('fax')
|
||||
if partner.get('email'):
|
||||
vobject_item.add('email').value = partner.get('email')
|
||||
if partner.get('website'):
|
||||
vobject_item.add('url').value = partner.get('website')
|
||||
if partner.get('function'):
|
||||
vobject_item.add('role').value = partner.get('function')
|
||||
if partner.get('comment'):
|
||||
vobject_item.add('note').value = partner.get('comment')
|
||||
if partner.get('category_id'):
|
||||
categs = [cls.categs.get(cid) for cid in partner.get('category_id')]
|
||||
vobject_item.add('categories').value = categs
|
||||
if partner.parent_id:
|
||||
vobject_item.add('org').value = [partner.parent_id.name]
|
||||
if partner.get('parent_id'):
|
||||
vobject_item.add('org').value = [partner.get('parent_id')[1]]
|
||||
vobject_item.add('rev').value = last_modified
|
||||
return vobject_item
|
||||
|
||||
@ -279,14 +290,11 @@ class Collection(BaseCollection):
|
||||
"""Fetch a single item from Odoo database"""
|
||||
model, database_id = href.split(':')
|
||||
database_id = int(database_id[:-len(self.content_suffix)])
|
||||
# fields = ['name', 'write_date', 'comment', 'street', 'street2', 'zip',
|
||||
# 'city', 'state_id' 'country_id']
|
||||
# data = self.odoo.execute(model, 'read', [database_id], fields)[0]
|
||||
record = self.odoo.env[model].browse([database_id])
|
||||
if model == 'res.partner':
|
||||
vobject_item = self._generate_vcard_from_odoo(record)
|
||||
vobject_item = self._generate_vcard_from_odoo(database_id)
|
||||
return self._get_item_from_vobject(href, vobject_item)
|
||||
elif model == 'calendar.event':
|
||||
record = self.odoo.env[model].browse([database_id])
|
||||
vobject_item = self._generate_ics_from_odoo(href, record)
|
||||
return self._get_item_from_vobject(href, vobject_item)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user