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 { PosStore } from "@point_of_sale/app/services/pos_store";
|
||||||
import { patch } from "@web/core/utils/patch";
|
import { patch } from "@web/core/utils/patch";
|
||||||
|
import { toRaw } from "@odoo/owl";
|
||||||
|
|
||||||
patch(PosStore.prototype, {
|
patch(PosStore.prototype, {
|
||||||
clearProductsCache() {
|
clearProductsCache() {
|
||||||
this._productsToDisplayCacheKey = null;
|
const rawStore = toRaw(this);
|
||||||
this._productsToDisplayCache = null;
|
rawStore._productsToDisplayCacheKey = null;
|
||||||
this._productToDisplayByCategCacheKey = null;
|
rawStore._productsToDisplayCache = null;
|
||||||
this._productToDisplayByCategCache = null;
|
rawStore._productToDisplayByCategCacheKey = null;
|
||||||
|
rawStore._productToDisplayByCategCache = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
async editProduct(product) {
|
async editProduct(product) {
|
||||||
@ -22,8 +24,9 @@ patch(PosStore.prototype, {
|
|||||||
const templatesLength = this.models["product.template"].length;
|
const templatesLength = this.models["product.template"].length;
|
||||||
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}`;
|
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}`;
|
||||||
|
|
||||||
if (this._productsToDisplayCacheKey === cacheKey && this._productsToDisplayCache) {
|
const rawStore = toRaw(this);
|
||||||
return this._productsToDisplayCache;
|
if (rawStore._productsToDisplayCacheKey === cacheKey && rawStore._productsToDisplayCache) {
|
||||||
|
return rawStore._productsToDisplayCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We override this getter to remove Odoo's hardcoded 100-product limit.
|
// We override this getter to remove Odoo's hardcoded 100-product limit.
|
||||||
@ -87,8 +90,8 @@ patch(PosStore.prototype, {
|
|||||||
result = this.orderProductBySequenceAndFav(filteredList);
|
result = this.orderProductBySequenceAndFav(filteredList);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._productsToDisplayCacheKey = cacheKey;
|
rawStore._productsToDisplayCacheKey = cacheKey;
|
||||||
this._productsToDisplayCache = result;
|
rawStore._productsToDisplayCache = result;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -99,16 +102,17 @@ patch(PosStore.prototype, {
|
|||||||
const categoriesLength = this.models["pos.category"].length;
|
const categoriesLength = this.models["pos.category"].length;
|
||||||
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}_${categoriesLength}`;
|
const cacheKey = `${searchWord}_${categoryId}_${templatesLength}_${categoriesLength}`;
|
||||||
|
|
||||||
if (this._productToDisplayByCategCacheKey === cacheKey && this._productToDisplayByCategCache) {
|
const rawStore = toRaw(this);
|
||||||
return this._productToDisplayByCategCache;
|
if (rawStore._productToDisplayByCategCacheKey === cacheKey && rawStore._productToDisplayByCategCache) {
|
||||||
|
return rawStore._productToDisplayByCategCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We override this getter to remove Odoo's hardcoded 100-product category limit.
|
// We override this getter to remove Odoo's hardcoded 100-product category limit.
|
||||||
const sortedProducts = this.productsToDisplay;
|
const sortedProducts = this.productsToDisplay;
|
||||||
if (!this.config.iface_group_by_categ) {
|
if (!this.config.iface_group_by_categ) {
|
||||||
const result = sortedProducts.length ? [["0", sortedProducts]] : [];
|
const result = sortedProducts.length ? [["0", sortedProducts]] : [];
|
||||||
this._productToDisplayByCategCacheKey = cacheKey;
|
rawStore._productToDisplayByCategCacheKey = cacheKey;
|
||||||
this._productToDisplayByCategCache = result;
|
rawStore._productToDisplayByCategCache = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,8 +158,8 @@ patch(PosStore.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._productToDisplayByCategCacheKey = cacheKey;
|
rawStore._productToDisplayByCategCacheKey = cacheKey;
|
||||||
this._productToDisplayByCategCache = results;
|
rawStore._productToDisplayByCategCache = results;
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user