Commit Graph
205 Commits
Author SHA1 Message Date
Christophe Simonis 4aa5ec3fa5 [MERGE] forward port branch 11.0 up to d67b410dfc 2018-03-07 18:46:38 +01:00
Raphael Collet b53c017052 [FIX] fields: use copy_cache during onchanges only
This fixes the bug introduced in rev 34c52e9938
that optimizes method `copy_cache`.
2018-03-05 11:25:37 +01:00
Christophe Simonis 3b959c313d [MERGE] forward port branch saas-11.1 up to a277b58507 2018-02-15 11:52:10 +01:00
Christophe Simonis a277b58507 [MERGE] forward port branch 11.0 up to 259686ba78 2018-02-15 10:58:08 +01:00
Raphael Collet 34c52e9938 [FIX] fields: performance of onchange on related fields
Optimize the copy of the cache being made by related fields to compute
themselves.  Instead of traversing records data in cache, follow the cache
structure itself and copy everything!

OPW 816125
2018-02-13 17:08:49 +01:00
Raphael Collet 869f062e08 [REF] models: improve code of _create/_write
Also remove method `self._check_selection_field_value`, and perform the check
in field method `convert_to_column`.
2018-01-16 10:47:13 +01:00
Christophe Simonis 03a36a9bba [MERGE] forward port branch saas-11.1 up to 56974322f8 2018-01-12 19:13:10 +01:00
Christophe Simonis 56974322f8 [MERGE] forward port branch 11.0 up to 3b80a059ff 2018-01-12 19:03:00 +01:00
Raphael Collet ca9d2b3006 [IMP] fields: log when a stored field depends on a non-stored field
Log an info when a field is computed and stored, but not all its dependencies
are stored.  Also allow to set explicitly `depends` on a field; this is useful
to restrict the dependencies of a related field.
2018-01-12 14:13:37 +01:00
Raphael Collet 3fbd86bcbe [IMP] field: compute transitive dependencies over non-stored fields
In other words, when a field F depends on a non-stored field G, it also depends
on G's dependencies.  This guarantees that whenever a dependency of G is
modified, F will be invalidated and marked to recompute (if necessary).

The transitive closure of dependencies is not computed over stored fields.
Anyway stored fields already trigger the recomputation of their dependent
fields during their recomputation.  The performance impact on the loading of a
registry is negligible (less than 1%), and the increase of recomputation
triggers is small (less than 10%).
2018-01-12 13:42:05 +01:00
Raphael Collet 309b6b8e5a [FIX] api: optimize odoo.api.Cache.get_records()
Assuming that `field.cache_key(record)` is independent from `record.id`,
compute the cache key once for all records, and avoid using `browse` on all
record ids.  This makes `get_records` about 20 times faster.

This has a good performance impact on `field.modified_draft()`, which is used
during onchanges for invalidating fields.
2018-01-11 13:52:16 +01:00
Christophe Simonis 4708812b6c [MERGE] forward port branch 11.0 up to b37cc1f9b7 2017-12-12 18:50:59 +01:00
Christophe Simonis b37cc1f9b7 [MERGE] forward port branch saas-16 up to a2ea4ba095 2017-12-12 18:39:43 +01:00
Christophe Simonis a2ea4ba095 [MERGE] forward port branch saas-15 up to 5701010d0d 2017-12-12 16:15:04 +01:00
Christophe Simonis 5701010d0d [MERGE] forward port branch saas-14 up to 744c2934b3 2017-12-12 15:35:11 +01:00
Christophe Simonis 744c2934b3 [MERGE] forward port branch 10.0 up to 219c93252f 2017-12-12 14:49:29 +01:00
Christophe Simonis 219c93252f [MERGE] forward port branch 9.0 up to 7a24a2f45f 2017-12-12 14:15:15 +01:00
Raphael Collet 6da1c3ac4c [FIX] fields: performance of convert_to_onchange on x2many fields
Suppose we convert a x2many field `foo_ids` with a many2one sub-field `bar_id`.
The conversion of the values of `bar_id` generates pairs `(id, name)`.  Before
this patch, the method `name_get` is invoked on every value, one by one.
Rewrite the code to ensure that `name_get()` is invoked on all values at once.
2017-12-06 15:56:25 +01:00
Christophe Simonis b8540eefe3 [MERGE] forward port branch saas-15 up to 970be94f37 2017-12-05 16:46:14 +01:00
Christophe Simonis 970be94f37 [MERGE] forward port branch saas-14 up to e9c2dcd28d 2017-12-05 14:52:16 +01:00
Lucas Perais (lpe) 2a86e9245c [FIX][BACKPORT] Always round monetary values in database
backport of afef71d6b9

Original commit message:

Let `create` and `write` round monetary field values before sending them to the
database. Pass the values to be written to `field.convert_to_column`, so that
the currency can be retrieved from the values, and the value be rounded.
2017-12-05 13:46:06 +01:00
Alexandre Kühn f38ace8de2 [DOC] fields: improve doc for trim attribute 2017-11-30 13:00:36 +01:00
Alexandre Kühn fb6c9c2443 [IMP] web: FieldChar trim its value by default
With this commit, we change the behaviour of the web client with respect
to spaces in char fields.  Most of the time, starting and ending spaces
have no value, and worse, make the data not so reliable.

After this commit, field char will trim by default (so, if the user input a
char as ' abc ', the string 'abc' will be sent to the server instead).
Note that this only applies when the value of the field is changed.  If
someone open a form view, then switches to edit mode and save, nothing
will change.

This is the desired behavior most of the time.  However, in some rare
cases, this is actually harmful.  For example, if we trim the
'decimal_point' field, it will not be possible to enter a whitespace as
decimal separator.  In those cases, we introduce a new attribute 'trim',
which allow the developer to desactivate that feature.
2017-11-24 13:09:10 +01:00
Christophe Simonis 1da064a1d3 [MERGE] forward port branch saas-16 up to 8ee9024a4c 2017-10-13 13:13:11 +02:00
Christophe Simonis aeae519a65 [MERGE] forward port branch saas-15 up to 945dd32eb0 2017-10-12 21:44:28 +02:00
Christophe Simonis 945dd32eb0 [MERGE] forward port branch saas-14 up to 91e2264b28 2017-10-12 18:43:14 +02:00
Christophe Simonis 91e2264b28 [MERGE] forward port branch 10.0 up to ba519bde84 2017-10-12 17:30:01 +02:00
Raphael Collet 10412d351c [FIX] fields: prefetching of related fields (#20017)
Prefetching is underused when all fields are traversed one record at a time.
So instead, traverse all records one field at a time.  This guarantees batch
prefetching/computation on every field being accessed.
2017-10-11 13:39:02 +02:00
Raphael Collet 0af8d4ffd2 [FIX] fields: performance optimization
Add a shortcut in `copy_cache`, to avoid iterating on all fields.
2017-10-11 11:55:02 +02:00
Christophe Simonis e1104ac344 [FIX] core: revert cb1cfadda2
Due to Cache reimplementation, this commit can't be applied as-it in
version 11.0 and need to be adapted correctly.

Undo PR #19963
2017-10-10 18:36:34 +02:00
Christophe Simonis 6c2ab192ea [MERGE] forward port branch saas-16 up to 88a9980b0c 2017-10-10 16:49:59 +02:00
Christophe Simonis 88a9980b0c [MERGE] forward port branch saas-15 up to 66945d3427 2017-10-10 14:15:24 +02:00
Christophe Simonis 66945d3427 [MERGE] forward port branch saas-14 up to 68d1ad5b7a 2017-10-10 13:27:29 +02:00
Christophe Simonis daa2194677 [MERGE] forward port branch 10.0 up to 0e28db88d1 2017-10-10 12:32:50 +02:00
Raphael Collet fcf6ef476c [FIX] fields: writing on a one2many with a domain should not remove all lines
Specifically, the command `(6, 0, ids)` should only unlink/detach the lines
that satisfy to the field's domain.

Test from #18440

opw-756983
2017-10-10 11:21:15 +02:00
Christophe Simonis 446ff1baf8 [MERGE] forward port branch saas-15 up to b60a41ce14 2017-10-09 17:54:36 +02:00
Christophe Simonis 6b0828b3bf [MERGE] forward port branch saas-14 up to 85c8000738 2017-10-09 13:24:17 +02:00
Christophe Simonis 85c8000738 [MERGE] forward port branch 10.0 up to cb1cfadda2 2017-10-09 12:44:22 +02:00
Raphael Collet cb1cfadda2 [FIX] fields: performance issue in copy_cache (#19963)
That function is called when computing related fields in onchange mode.
The new implementation makes a direct access to the cache's implementation.

opw-772303
2017-10-09 11:53:18 +02:00
Raphael Collet e671679183 [FIX] fields: do not use int() to retrieve record id
When reading a one2many field, the inverse field of the retrieved lines may
already be assigned in cache to a new record.  This can happen during an
onchange.  In that case, the algorithm crashes.  Let's clean it up!
2017-09-26 11:43:37 +02:00
Raphael Collet c6b184bb23 [FIX] fields: optimize many2many command (6, 0, ids) on new records
The command does not need to remove existing relations, as there is no relation
yet on new records.  This saves one query per many2many field with that command
in a `create`.
2017-09-21 16:10:13 +02:00
Raphael Collet 49f6a1b544 [FIX] fields: improve performance of many2many fields
An update by a list of commands is now guaranteed to have at most three SQL
queries to update the relation, whatever the number of commands and records.
2017-09-20 13:30:56 +02:00
Raphael Collet 886003af93 [FIX] models: in onchange, consider all levels of subfields 2017-09-13 10:12:16 +02:00
Raphael Collet d7190a3fd0 [IMP] api: reindex the record cache to improve cache hit
The record cache is indexed by `(field, record_id, key)`, where `key` depends
on the environment.  The key is either `(cr, uid, context)` or `(cr, uid)`,
depending on whether the field's value is context-dependent.  As most fields
are not context-dependent, this should avoid some cache prefetching when
swiching context.
2017-09-08 13:21:00 +02:00
Raphael Collet 32a58c0db3 [REF] api: wrap the record cache implementation into a class
This makes the rest of the ORM independent from the cache's implementation, and
rely on a well-defined API instead.
2017-09-08 13:21:00 +02:00
Raphael Collet 64e945aa44 [REF] models: make the API of RecordCache more consistent
Make `RecordCache` work on a single record only, and implement a mapping from
field names (only) to values.

Also add explicit methods on `RecordCache` to wrap special behavior in cache,
and simplify all special values as a wrapper for a getter function.

The record cache may contain regular and special values.  Modify `RecordCache`
so that only methods ending with `_value` check for regular values.  The
dictionary methods considers both regular and special values as equivalent.

    name in record._cache               # test if cache has a value
    iter(record._cache)                 # iterate on values
    record._cache[name]                 # get value
    record._cache.get(name)             # get value or default

    record._cache.has_value(name)       # test if cache has a regular value
    record._cache.get_value(name)       # get regular value or default
2017-09-08 13:21:00 +02:00
Raphael Collet 6cf98c4c87 [IMP] models: in onchange, keep track of virtual ids of new records
The x2many "create" command is now like: `(0, ref, vals)`, where `ref` is an
arbitrary reference that may be used to identify a new line in the relation.
The reference is returned in a similar command by the method `onchange`.
`onchange` now supports self-modifying x2many fields.
2017-08-30 14:38:29 +02:00
Olivier Dony 695716efb0 [FIX] P3: remove pycompat.{keys,items,values} helpers
Now that we're closer to switching to P3 for good, these helpers have
outlived their usefulness, and mostly add noise.

All remaining dict.iter*() or dict.view*() must be converted to the
normal keys(), values() or items() calls.

Whenever the result is likely to be used for more than the scope of a
loop, or when the dict needs to be modified during iteration, the calls
must be wrapped in a ``list()``, to protect the new P3 semantics.
Those cases are very exceptional.

Also removed some dead code or improved the API to remove unnecessary
conversions.
2017-08-20 23:25:54 +02:00
Xavier Morel 364becdab1 [FIX] P3: text/binary handling
* unichr -> pycompat (builtin removed from Python 3, ``chr`` has
  become unicode-aware)
* Psycopg2 bytea values (binary fields) are returned as memoryviews in
  P3 but buffers in P2
* Both bytes and (text) strings are conventionally iterable in
  P3 (they have a __iter__ method), so fix up the exclusion pattern
  for flatten
2017-08-20 23:25:54 +02:00
Xavier Morel 7dd062f835 [FIX] P3: text model types
* remove references to basestring & unicode (use relevant pycompat
  helpers)
* remove some str calls (either entirely or replaced by relevant
  helper, either text or native)
* use better API to avoid unnecessary conversions
* remove some XML declarations in views
2017-08-20 23:25:54 +02:00