Commit Graph
3175 Commits
Author SHA1 Message Date
Nans Lefebvre 738e60c6eb [FIX] service: fix integrity error display
During the installation of a module, an IntegrityError can be raised,
e.g. if some module data already exists in the database
(as in the case of a module which uninstallation did not remove its data).

In Python2 it was possible to use such a psycopg2.IntegrityError with i[0]
to get its error message, while this raises an exception in Python3,
i.args[0] is needed.

As a result the log would contain an exception within an exception instead of
displaying an error to the user.

opw 1916374

closes odoo/odoo#29787
2018-12-28 14:27:11 +00:00
Odoo Translation Bot 5d237b2037 [I18N] Update translation terms from Transifex 2018-12-23 03:12:41 +01:00
Denis Ledoux 189cc4405c [IMP] api: improve storing performance of the api cache
This revision moves the `cache_key` to the first level
dict of the cache, instead of the last one.

Doing so, we reduce the number of times the reference
to the cache key is stored in the dict.

For instance,
for 100.000 records, 20 fields and 2 env (e.g. with and without sudo)
formerly, there were 100.000 * 20 * 2 occurences of cache key references
now, there is only 2 references.

Storing references to an object consumes memory.
Therefore, by reducing the number of object references
in the cache, we reduce the memory consumed by the cache.
Also, we reduce the time to access a value in the cache
as the cache size is smaller.

The time and memory consumption are therefore improved,
while keeping the advantages of revision
d7190a3fd0
which was about sharing the cache of fields
which do not depends on the context, but
only on the cursor and user id.

This revision relies on the fact there are less different references
to the cache key then references to fields/records.
Indeed, this is more likely to have 100.000 different records stored
in the cache rather than 100.000 different environments.

Here is the Python proof of concept that was used
to make the conclusion that setting the cache_key
in the first level dict of the cache is more efficient.
```Python
import os
import psutil
import time

from collections import defaultdict

cr = object()
uid = 1
fields = [object() for i in range(20)]
number_items = 500000

p = psutil.Process(os.getpid())
m = p.memory_info().rss
s = time.time()

cache_key = (cr, uid)
cache = defaultdict(lambda: defaultdict(dict))
for field in fields:
    for i in range(number_items):
        cache[field][i][cache_key] = 5.0
        # cache[cache_key][field][i] = 5.0

print('Memory: %s' % (p.memory_info().rss - m,))
print('Time: %s' % (time.time() - s,))

```
- Using `cache[field][i][cache_key]`:
   - Time: 3.17s
   - Memory: 3138MB
- Using `cache[cache_key][field][i]`:
   - Time: 1.43s
   - Memory: 756MB

Even worse, when the cache key tuple is instantiated inside the loop,
for the former cache structure (e.g. `cache[field][i][(cr, uid)]`),
the time goes from 3.17s to 25.63s and the memory from 3138MB to 3773MB

Here is the same proof of concept, but using the Odoo API and Cache:
```Python
import os
import psutil
import time

from odoo.api import Cache

model = env['res.users']
records = [model.new() for i in range(100000)]

p = psutil.Process(os.getpid())
m = p.memory_info().rss
s = time.time()

cache = Cache()
char_fields = [field for field in model._fields.values() if field.type == 'char']
for field in char_fields:
    for record in records:
        cache.set(record, field, 'test')

print('Memory: %s' % (p.memory_info().rss - m,))
print('Time: %s' % (time.time() - s,))
```
- Before (`cache[field][record_id][cache_key]` and cache_key tuple instantiated in the loop):
   - Time: 4.12s
   - Memory: 810MB
- After (`cache[cache_key][field][record_id]` and cache_key tuple stored in the env and re-used):
   - Time: 1.63s
   - Memory: 125MB

This can be played in an Odoo shell, for instance
by storing it in `/tmp/test.py`, and then
piping it to the Odoo shell:
`cat /tmp/test.py | ./odoo-bin shell -d 12.0`

closes odoo/odoo#29676
2019-01-03 12:39:04 +00:00
Denis Ledoux f70877b040 [IMP] api: gain some memory by not creating the cache_key tuple multiple times 2019-01-03 12:39:04 +00:00
Raphael Collet cdc01c50b3 [FIX] base: missing tests on record cache 2019-01-03 12:39:04 +00:00
Laurent Smet 67d3d30cf2 [FIX] tools/date_utils: Fix get_fiscal_year with leap years
Suppose calling get_fiscal_year(date, day=29, month=2) with date(year=2017, month=2, day=28)

The computation steps are:
date_from = date(year=2017, month=2, day=28) - 1 year = date(year=2016, month=2, day=28)
date_from = date_from + 1 day = date(year=2016, month=2, day=29)

It's incorrect because the value of date_from must be date(year=2016, month=3, day=1)

closes odoo/odoo#29416
2019-01-03 08:30:31 +00:00
Kirti Choudhary 78feb99009 [IMP] base: fix demo data
closes odoo/odoo#30725
2019-01-31 11:12:16 +00:00
Denis Ledoux 36551615b7 [IMP] read, cache: faster read by updating the cache by fields
instead of updating the cache by records.

We use `cr.fetchall()` and `zip` to get the values by field, which is more
convenient to be stored in cache.

Result of `cr.fetchall()`:
```
[
    (3, 'Marc Demo', 'demo@example.com', '032'),
    (1, 'Mitchell Admin', 'admin@example.com', '001'),
]
```
After being grouped by field:
```
[
    [3, 1],
    ['Marc Demo', 'Mitchell Admin],
    ['demo@example.com', 'admin@example.com'],
    ['032', '001'],
]
```

That way we can update the cache of a field for all records at once, by calling
the builtin `update` method of `dict` with the `zip` of record ids and
corresponding values.

This significantly speeds up the storage of field values in the cache.

closes odoo/odoo#30817
2019-02-11 16:22:01 +00:00
Denis Ledoux cb0e8831f9 [IMP] models: read, faster missing algorithm
Instead of fetching the cache values of records that will eventually be
removed, skip fetching values of a record as soon as we know a it is missing.
2019-02-11 15:54:21 +00:00
Denis Ledoux ecbc18ad8d [IMP] models: read, speed up by avoiding the use of indexation
Instead of iterating on self and then putting the values in the right place in
the `data` dict, iterate over data directly.

This removes the need of the indexing `data[record]`, which takes a significant
time when dealing with hundred of thousands of records.
2019-02-11 15:53:20 +00:00
Denis Ledoux ce0575ef27 [IMP] models: faster ensure_one implementation
Calling `len` on a long list and checking that its value is 1 is slower than
just unpacking the list.  The point is to check whether there is just one item
in the list, and counting all items just for that is a bit overkill.
2019-02-11 15:50:51 +00:00
Denis Ledoux dcc752aaab [IMP] models: faster browse records iteration
By avoiding to update the prefetch ids for each record when iterating on
recordsets.  This is faster when iterating on very large recordsets.
2019-02-11 15:49:21 +00:00
Denis Ledoux 681ff1aec1 [IMP] fields: faster convert_to_record for many2one fields
Use `env.registry` instead of `env` to get the comodel as a class instead of an
instance, which saves one call to `_browse` each time we access a relational
field.  This saves time because of the cost of `object.__new__` and prefetch
update in `_browse`.
2019-02-11 15:45:57 +00:00
Denis Ledoux 368751b938 [IMP] api: avoid record.id indirections
The cache is quite time critical, as it is accessed millions times when reading
multiple fields on hundred of thousands of records.

Avoiding indirections and `if` statement when possible speeds up the cache
access time.
2019-02-11 15:45:36 +00:00
Denis Ledoux 600c8b3e65 [IMP] fields: faster record.id access
This is a partial backport of revision
ed32700925132943fc4957ae2f43deaeeec7a278

to speed up the access of browse record id field.
2019-02-11 15:45:25 +00:00
Odoo Translation Bot 0b61a7d135 [I18N] Update translation terms from Transifex 2019-02-10 03:13:22 +01:00
Odoo Translation Bot 439e818953 [I18N] Update translation terms from Transifex 2018-12-16 03:13:51 +01:00
Odoo Translation Bot 94a3b3ca8f [I18N] Update translation terms from Transifex 2019-01-27 06:03:55 +01:00
Odoo Translation Bot 0efff5f030 [I18N] Update translation terms from Transifex 2019-01-21 16:49:26 +01:00
Christophe Simonis a337b9ec92 [MERGE] forward port branch 12.0 up to f854e01a98 2019-01-18 14:26:33 +01:00
Nicolas Seinlet f8e37d6a80 [IMP] improve overridden sql constraints support
If module A define an sql constraints and module B, which depends on 
module A, override the sql constraint, we must ensure having only the 
last definition in constraints list. Having the two versions in the list
makes the ORM continuously trying to drop the second version by the 
first one, then recreate the second version, when performing operations 
like an upgrade a module B.

An illustration of this is the login_key on res.users, which is unique
per login in base, but unique per (login, website) in website.

closes odoo/odoo#30334
2019-01-18 09:20:02 +00:00
Martin Trigaux bfe1e20d6b [I18N] export saas-12.1 source terms
To reflect fixes at ec2263080a and cd4080839f

closes odoo/odoo#30253
2019-01-16 10:35:49 +00:00
Christophe Simonis ea51fe5130 [FIX] base: adapt forward-ported test to new version 2019-01-14 11:11:22 +01:00
Christophe Simonis 3cbc9dd6c0 [MERGE] forward port branch 12.0 up to 6a0675d36d 2019-01-14 10:34:50 +01:00
Pierre Masereel 976429c8c6 [FIX] base: fix demo data
Since changes made in this commit: https://github.com/odoo/odoo/commit/f598c3e597fa0b7f0e875dadf163ccea44a04e06
The address didn't work anymore for any of delivery tests

closes odoo/odoo#30156
2019-01-11 16:02:08 +00:00
Christophe Simonis 8aa8548d8a [MERGE] forward port branch 12.0 up to 3e4138deaa
closes odoo/odoo#30045
2019-01-09 15:56:53 +00:00
Martin Trigaux af69902ecc [I18N] export saas-12.1 source terms
closes odoo/odoo#29730
2018-12-24 11:07:31 +00:00
Sébastien Theys 1fa10cbc5d [FIX] base,website_google_map: fix partner address not showing
Following commit 983c7e8152.

`_compute_display_name` is overridden in partner to force `show_adress` and some
other context variables to None. When those values are in the context, calling
`display_name` can give a different result than calling `name_get()[0][1]`.

This commit reverts the changes of the mentioned commit where the behavior is
actually different, that is, when `show_address` is in the context.

It also adds a comment on the `_compute_display_name` method to avoid further
mistakes.

closes odoo/odoo#29510
2018-12-13 11:17:23 +00:00
Odoo Translation Bot 91382f691d [I18N] Update translation terms from Transifex 2018-12-30 01:30:16 +01:00
Antoine Prieels (ANP) e338deb223 [IMP] base: Add context key to force the rendering of the pdf in 'test-enabled' mode
In `test_enable` mode, `render_qweb_pdf` fallbacked to `render_qweb_html`. We add a context key to be able to force the rendering of the pdf, even in `test-enable` mode.
2018-12-26 10:11:05 +00:00
Christophe Simonis 7e5d5045bf [MERGE] forward port branch saas-15 up to 1ace2ed88b 2018-12-11 16:20:34 +01:00
Christophe Simonis 1ace2ed88b [MERGE] forward port branch saas-14 up to 5a147acf1b 2018-12-11 15:11:32 +01:00
Christophe Simonis 5a147acf1b [MERGE] forward port branch 10.0 up to f69c004795 2018-12-11 14:33:39 +01:00
Christophe Simonis f351dd8cab [MERGE] forward port branch 12.0 up to 047e2b28de 2018-12-12 11:38:25 +01:00
Christophe Simonis 069278b652 [MERGE] forward port branch saas-11.3 up to 55dafc20f6 2018-12-11 18:51:05 +01:00
Christophe Simonis 55dafc20f6 [MERGE] forward port branch 11.0 up to 7e5d5045bf 2018-12-11 17:06:48 +01:00
Raphael Collet befb3a1cd6 [FIX] models: make valid aggregation functions explicit
In `read_group`, allow an explicit set of aggregation functions.

closes odoo/odoo#29348
2018-12-10 08:52:50 +00:00
Christophe Monniez 36870481f9 [REL] saas-12.1 2018-12-08 07:36:21 +01:00
Raphael Collet 54238c88e8 [FIX] mail: wrong many2many definition
The definition of `attachment_ids` on model `email_template.preview` is wrong,
because its table/columns refer to the model `mail.template`.  As the field is
only used to preview a result in a wizard form, it does not need to be stored.

closes odoo/odoo#29349
2018-12-07 12:28:58 +00:00
7d85ab1eac [REF] base, *: refactor binary_content
*: tools, web, website, website_forum, mail, im_livechat

This commit refactors ir_http to make it more readable
and flexible.

Move the resize function of web/image to odoo.tools

Co-authored-by: XavierDo <xdo@odoo.com>
Co-authored-by: Antony Lesuisse <al@openerp.com>

closes: #28563
task: #1908896
2018-12-06 19:09:33 +00:00
ThanhDodeurOdoo 89f20d2c29 [REF] base, mail: splits the documents feature from ir attachment
Moved the field 'active', 'res_model_name' and 'thumbnail' from
ir.attachment to enterprise's documents.document.

Moved the pdf split feature to enterprise's Documents module.

task: #1908896
2018-12-06 19:09:33 +00:00
Odoo Translation Bot 77e7d952b4 [I18N] Update translation terms from Transifex 2018-12-09 03:15:09 +01:00
Odoo Translation Bot b234af04c1 [I18N] Update translation terms from Transifex 2018-12-24 12:51:19 +01:00
Odoo Translation Bot 47aae6faba [I18N] Update translation terms from Transifex 2018-12-23 01:29:13 +01:00
Olivier Dony eb19016ba3 [REV] Revert "[FIX] modules: load demo data fallback"
This reverts commit 5f4a945182.
The cure is worse than the original disease.

The main installation cursor often holds exclusive locks (due to DDL
changes) on vital tables such as res_users. As a result, using
another cursor to perform changes while the main cursor is waiting
is extremely deadlock-prone. And these deadlocks can't be detected by
PostgreSQL as they mix Python-SQL locking, which leads to deadlocked
HTTP workers.

Related to:
- opw-1916918
- #29528
2018-12-21 16:01:31 +01:00
Christophe Simonis d4c65a7ede [MERGE] forward port branch 11.0 up to 2156af480f 2018-12-04 17:11:57 +01:00
Christophe Simonis 2156af480f [MERGE] forward port branch saas-15 up to 9bfc12cb3f 2018-12-04 16:17:49 +01:00
Odoo Translation Bot ec4ee14c89 [I18N] Update translation terms from Transifex 2018-12-09 01:16:26 +01:00
Goffin Simon f86b9ff3c4 [FIX] base: Upgrading a module with deleted models
Steps to reproduce the bug:

- Write a model in lunch.py called "my.model"
- Install module Lunch
- Erase "my.model" in lunch.py
- Upgrade the module Lunch

A error was raised when processing function "_process_end" because
the ir.model.data record of "my.model" was not deleted

opw:1908813

closes odoo/odoo#29247
2018-12-05 15:39:02 +00:00
Christophe Simonis caf1837216 [MERGE] forward port branch saas-11.3 up to d4c65a7ede 2018-12-05 12:27:57 +01:00