diff options
| author | Ivan Yelizariev <iel@odoo.com> | 2021-02-19 14:02:44 +0000 |
|---|---|---|
| committer | Ivan Yelizariev <iel@odoo.com> | 2021-02-19 15:38:25 +0000 |
| commit | fe7718d02f7539959616b0e6f56d4354c768339b (patch) | |
| tree | c2dbadd7d8c6feaabadaf5dd17972868a947f544 /addons/pos_cache/static | |
| parent | b7e7029829915581056f3d79a36e3c2f60cc02f2 (diff) | |
[FIX] pos_cache: load products by batches
pos_cache is used to speed up opening POS in databases with large number of
products. In some cases it's still not enough and thousands of records cannot be
cached in a single request, because reading information may take more time than
maximum allowed.
As a workaround, this commit adds posibility to split request into few small
requests. To activate the feature set system parameter
``pos_cache.limit_products_per_request`` to appropriate value depending on your
server capacity.
---
opw-2439347
closes odoo/odoo#66539
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_cache/static')
| -rw-r--r-- | addons/pos_cache/static/src/js/pos_cache.js | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/addons/pos_cache/static/src/js/pos_cache.js b/addons/pos_cache/static/src/js/pos_cache.js index 4f840082fb1..48dfbd4a745 100644 --- a/addons/pos_cache/static/src/js/pos_cache.js +++ b/addons/pos_cache/static/src/js/pos_cache.js @@ -31,18 +31,56 @@ models.PosModel = models.PosModel.extend({ // other modules) in js. var product_fields = typeof self.product_model.fields === 'function' ? self.product_model.fields(self) : self.product_model.fields; var product_domain = typeof self.product_model.domain === 'function' ? self.product_model.domain(self) : self.product_model.domain; - var records = rpc.query({ + var limit_products_per_request = self.config.limit_products_per_request; + var cur_request = 0; + function next(resolve, reject){ + var domain = product_domain; + if (limit_products_per_request){ + domain = domain.slice(); + // implement offset-limit via id, because "pos.cache" + // doesn't have such fields and we can add them in master + // branch only + domain.unshift(['id', '>', cur_request * limit_products_per_request], + ['id', '<=', (cur_request + 1) * limit_products_per_request]); + } + return rpc.query({ model: 'pos.config', method: 'get_products_from_cache', - args: [self.pos_session.config_id[0], product_fields, product_domain], + args: [self.pos_session.config_id[0], product_fields, domain], + }).then(function (products) { + self.db.add_products(_.map(products, function (product) { + product.categ = _.findWhere(self.product_categories, {'id': product.categ_id[0]}); + product.pos = self; + return new models.Product({}, product); + })); + if (limit_products_per_request) { + cur_request++; + // check that we have more products + domain = product_domain.slice(); + domain.unshift(['id', '>', cur_request * limit_products_per_request]); + rpc.query({ + model: 'product.product', + method: 'search_read', + args: [domain, ['id']], + kwargs: { + limit: 1, + } + }).then(function (products) { + if (products.length){ + next(resolve, reject); + } else { + resolve(); + } + }); + } else { + resolve(); + } }); + } self.setLoadingMessage(_t('Loading') + ' product.product', 1); - return records.then(function (products) { - self.db.add_products(_.map(products, function (product) { - product.categ = _.findWhere(self.product_categories, {'id': product.categ_id[0]}); - product.pos = self; - return new models.Product({}, product); - })); + + return new Promise((resolve, reject) => { + next(resolve, reject); }); }); }, |
