From 3ae9e91bcd68605ec776dc941246fbd9d82ab5c0 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sun, 27 Aug 2017 14:04:23 +0530 Subject: [PATCH] Add memoization in search --- erpnext/selling/page/point_of_sale/point_of_sale.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js index 236e923255..a3ea04e201 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -808,12 +808,23 @@ class POSItems { filter_items(search_term) { search_term = search_term.toLowerCase(); + + // memoize + this.search_index = this.search_index || {}; + if (this.search_index[search_term]) { + const items = this.search_index[search_term]; + this.render_items(items); + return; + } + this.get_items({search_value: search_term}) .then((items) => { + this.search_index[search_term] = items; + this.render_items(items); if(this.serial_no) { this.events.update_cart(items[0].item_code, - 'serial_no', this.serial_no) + 'serial_no', this.serial_no); } }); }