This question has been flagged
1 Reply
3505 Views

I've integrated several remote webservices into our Odoo EE v9.

My goal is:

  1. to call the webservice on create (so after the ORM grants authorization).

  2. call the remote service only once, not more.

  3. if this call succeeded before? return existing record.

  4. [optionally] work on a separate transaction to avoid unnecessary rollbacks.

I've created two flavors:

  • create -> call webservice

  • create -> do nothing until -> read computed field (stored/rw) -> call webservice

Both methods end up in an uncontrollable entanglement of computations and recomputations. This happend majorly inside the cache layer and I can't unravel what's happening when. Sometimes it calls 3 times, sometimes more. Sometimes I open a parent and recomputations happen eventhough store=True. I've also tried with env.norecompute.

Is there anyone who holds some kind of lifecycle documentation on the cache? Does cache gets written by convert_to_cache on a field (and on a record)? What happens when cache gets invalidated? How can I use a computed stored field that calculates exactly once? These are all questions I can't find an answer to, even though I have put a lot of effort in them.


Regards,

Rik


p.s. Some interesting "closer to the cache" tech docs from Raphael Collet:

https://www.odoo.com/nl_NL/slides/slide/advanced-features-of-the-api-206

https://www.odoo.com/nl_NL/slides/slide/how-to-optimize-the-performance-229/pdf_content

Avatar
Discard
Best Answer

Dear Rik,

The scenario you describe is confusing to me...

  • What does the data model on which you call create() represent?

  • You mention a computed field that gets recomputed.  What is that field?  What value does it store?  What is the link between that field and the webservice?

  • What kind of remote webservice do you use?  You wrote is should be called only once.  But is it once for all, once per server instance, once per request?

The "cache" you mention is the record cache.  It is a caching layer between the database and the record objects.

  • It is essentially a mapping from a pair (record, field) to a value.

  • The cache is written explicitly by field assignments like record.name = "foo", or implicitly by a prefetching mechanism that reads data from the database when you access a field like record.name.

  • A cache entry (record, field) is invalidated automatically when that field is modified in the database, or when dependencies of the field have been modified (this forces its recomputation).

  • It is used both for performance (minimize the number of queries to read data from the database), and to memoize the result of computed fields.

  • The cache is attached to a transaction (JSON/RPC request), and is dropped at the end of the transaction.  It is therefore not shared across transactions.

Regards,

Raphael

Avatar
Discard