From 81ffada41c60272b1a6a0696f51a634f778cc595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 11 Jan 2013 15:41:08 +0100 Subject: [PATCH 1/3] [IMP] point_of_sale: added some comments about the localstorage db implementation and performance bzr revid: fva@openerp.com-20130111144108-5u4ie3p9ueoj6ulm --- addons/point_of_sale/static/src/js/db.js | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index 0df57759156..666c61919da 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -1,8 +1,34 @@ function openerp_pos_db(instance, module){ - /* PosLS is a LocalStorage based implementation of the point of sale database, - it performs better for few products, but does not scale beyond 500 products. - */ + /* The db module was intended to be used to store all the data needed to run the Point + * of Sale in offline mode. (Products, Categories, Orders, ...) It would also use WebSQL + * or IndexedDB to make the searching and sorting products faster. It turned out not to be + * a so good idea after all. + * + * First it is difficult to make the Point of Sale truly independant of the server. A lot + * of functionality cannot realistically run offline, like generating invoices. + * + * IndexedDB turned out to be complicated and slow as hell, and loading all the data at the + * start made the point of sale take forever to load over small connections. + * + * LocalStorage has a hard 5.0MB on chrome. For those kind of sizes, it is just better + * to put the data in memory and it's not too big to download each time you launch the PoS. + * + * So at this point we are dropping the support for offline mode, and this module doesn't really + * make sense anymore. But if at some point you want to store millions of products and if at + * that point indexedDB has improved to the point it is usable, you can just implement this API. + * + * You would also need to change the way the models are loaded at the start to not reload all your + * product data. + */ + + /* PosLS is a localstorage based implementation of the point of sale database. + * FIXME: The Products definitions and categories are stored on the locastorage even tough they're + * always reloaded at launch. This could induce a slowdown because the data needs to be reparsed from + * JSON before each operation. If you have a huge amount of products (around 25000) it can also + * blow the 5.0MB localstorage limit. + */ + module.PosLS = instance.web.Class.extend({ name: 'openerp_pos_ls', //the prefix of the localstorage data limit: 100, // the maximum number of results returned by a search @@ -110,6 +136,8 @@ function openerp_pos_db(instance, module){ }, /* saves a record store to the database */ save: function(store,data){ + var str_data = JSON.stringify(data); + console.log('Storing '+ Math.round(str_data.length/1024.0)+' KB of data to store: '+store); localStorage[this.name + '_' + store] = JSON.stringify(data); this.cache[store] = data; }, From 60dbad5bd58c98a6f70b3670310a674eeca7ce05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 11 Jan 2013 15:42:19 +0100 Subject: [PATCH 2/3] [FIX] point_of_sale: removed console.logs bzr revid: fva@openerp.com-20130111144219-eg0xr5kzwewq5ygf --- addons/point_of_sale/static/src/js/models.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index f533fa760ab..556ea482aad 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -125,7 +125,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal return self.fetch('res.partner', ['name','ean13'], [['ean13', '!=', false]]); }).then(function(partners){ self.set('partner_list',partners); - console.log('Loaded partners:',partners); return self.fetch('account.tax', ['amount', 'price_include', 'type']); }).then(function(taxes){ @@ -242,7 +241,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // saves the order locally and try to send it to the backend. 'record' is a bizzarely defined JSON version of the Order push_order: function(record) { - console.log('PUSHING NEW ORDER:',record); this.db.add_order(record); this.flush(); }, @@ -259,7 +257,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // it has been confirmed that they have been sent correctly. flush: function() { //TODO make the mutex work - console.log('FLUSH'); //this makes sure only one _int_flush is called at the same time /* return this.flush_mutex.exec(_.bind(function() { @@ -275,7 +272,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal var self = this; var orders = this.db.get_orders(); self.set('nbr_pending_operations',orders.length); - console.log('TRYING TO FLUSH ORDER:',index,'Of',orders.length); var order = orders[index]; if(!order){ @@ -291,7 +287,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }) .done(function(){ //remove from db if success - console.log('Order successfully sent'); self.db.remove_order(order.id); self._flush(index); }); From a480cff6f5d6b0ec7c72410fff4c399ae73d14f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 11 Jan 2013 15:42:55 +0100 Subject: [PATCH 3/3] [FIX] point_of_sale: removed console.logs bzr revid: fva@openerp.com-20130111144255-cgs85ue7hsp5ces7 --- addons/point_of_sale/static/src/js/devices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 55e75ebcf42..e7d0376938c 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -438,7 +438,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // The barcode readers acts as a keyboard, we catch all keyup events and try to find a // barcode sequence in the typed keys, then act accordingly. $('body').delegate('','keyup', function (e){ - console.log('keyup:'+String.fromCharCode(e.keyCode)+' '+e.keyCode,e); + //console.log('keyup:'+String.fromCharCode(e.keyCode)+' '+e.keyCode,e); //We only care about numbers if (e.keyCode >= 48 && e.keyCode < 58){