I've integrated several remote webservices into our Odoo EE v9.
My goal is:
to call the webservice on create (so after the ORM grants authorization).
call the remote service only once, not more.
if this call succeeded before? return existing record.
[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.
p.s. Some interesting "closer to the cache" tech docs from Raphael Collet:
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.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 6/21/16, 12:14 PM|
|Seen: 248 times|
|Last updated: 7/5/16, 7:46 AM|