refactor: use toRaw for accessing internal caches in PosStore patch to avoid reactivity overhead
This commit is contained in:
parent
6173399c87
commit
bb75a58ca9
@ -2,13 +2,15 @@
|
||||
|
||||
import { PosStore } from "@point_of_sale/app/services/pos_store";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { toRaw } from "@odoo/owl";
|
||||
|
||||
patch(PosStore.prototype, {
|
||||
clearProductsCache() {
|
||||
this._productsToDisplayCacheKey = null;
|
||||
this._productsToDisplayCache = null;
|
||||
this._productToDisplayByCategCacheKey = null;
|
||||
this._productToDisplayByCategCache = null;
|
||||
const rawStore = toRaw(this);
|
||||
rawStore._productsToDisplayCacheKey = null;
|
||||
rawStore._productsToDisplayCache = null;
|
||||
rawStore._productToDisplayByCategCacheKey = null;
|
||||
rawStore._productToDisplayByCategCache = null;
|
||||
},
|
||||
|
||||
async editProduct(product) {
|
||||
@ -22,8 +24,9 @@ patch(PosStore.prototype, {
|
||||
const templatesLength = this.models["product.template"].length;
|
||||
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}`;
|
||||
|
||||
if (this._productsToDisplayCacheKey === cacheKey && this._productsToDisplayCache) {
|
||||
return this._productsToDisplayCache;
|
||||
const rawStore = toRaw(this);
|
||||
if (rawStore._productsToDisplayCacheKey === cacheKey && rawStore._productsToDisplayCache) {
|
||||
return rawStore._productsToDisplayCache;
|
||||
}
|
||||
|
||||
// We override this getter to remove Odoo's hardcoded 100-product limit.
|
||||
@ -87,8 +90,8 @@ patch(PosStore.prototype, {
|
||||
result = this.orderProductBySequenceAndFav(filteredList);
|
||||
}
|
||||
|
||||
this._productsToDisplayCacheKey = cacheKey;
|
||||
this._productsToDisplayCache = result;
|
||||
rawStore._productsToDisplayCacheKey = cacheKey;
|
||||
rawStore._productsToDisplayCache = result;
|
||||
return result;
|
||||
},
|
||||
|
||||
@ -99,16 +102,17 @@ patch(PosStore.prototype, {
|
||||
const categoriesLength = this.models["pos.category"].length;
|
||||
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}_${categoriesLength}`;
|
||||
|
||||
if (this._productToDisplayByCategCacheKey === cacheKey && this._productToDisplayByCategCache) {
|
||||
return this._productToDisplayByCategCache;
|
||||
const rawStore = toRaw(this);
|
||||
if (rawStore._productToDisplayByCategCacheKey === cacheKey && rawStore._productToDisplayByCategCache) {
|
||||
return rawStore._productToDisplayByCategCache;
|
||||
}
|
||||
|
||||
// We override this getter to remove Odoo's hardcoded 100-product category limit.
|
||||
const sortedProducts = this.productsToDisplay;
|
||||
if (!this.config.iface_group_by_categ) {
|
||||
const result = sortedProducts.length ? [["0", sortedProducts]] : [];
|
||||
this._productToDisplayByCategCacheKey = cacheKey;
|
||||
this._productToDisplayByCategCache = result;
|
||||
rawStore._productToDisplayByCategCacheKey = cacheKey;
|
||||
rawStore._productToDisplayByCategCache = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -154,8 +158,8 @@ patch(PosStore.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
this._productToDisplayByCategCacheKey = cacheKey;
|
||||
this._productToDisplayByCategCache = results;
|
||||
rawStore._productToDisplayByCategCacheKey = cacheKey;
|
||||
rawStore._productToDisplayByCategCache = results;
|
||||
return results;
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user