From 01042fde5e6f5b5e1968167881f1d40894779d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 23 Aug 2013 11:27:53 +0200 Subject: [PATCH 1/8] Use a better strategy to load by bunch trees review1034002 --- src/model.js | 70 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/src/model.js b/src/model.js index b926521656..8c23d410dc 100644 --- a/src/model.js +++ b/src/model.js @@ -381,32 +381,6 @@ loading = (this.model.fields[name].description.loading || 'eager'); } - if (~this.group.indexOf(this) && (loading == 'eager')) { - var idx = this.group.indexOf(this); - var length = this.group.length; - var n = 1; - while (Object.keys(id2record).length && - ((idx - n >= 0) || (idx + n < length)) && - n < 100) { - var record; - if (idx - n >= 0) { - record = this.group[idx - n]; - if (!(name in record._loaded) && - (record.id >= 0)) { - id2record[record.id] = record; - } - } - if (idx + n < length) { - record = this.group[idx + n]; - if (!(name in record._loaded) && - (record.id >= 0)) { - id2record[record.id] = record; - } - } - n++; - } - } - var context = jQuery.extend({}, this.get_context()); var fnames = []; if (loading == 'eager') { for (fname in this.model.fields) { @@ -436,6 +410,48 @@ fnames_to_fetch.push('rec_name'); } fnames_to_fetch.push('_timestamp'); + + var context = jQuery.extend({}, this.get_context()); + if (loading == 'eager') { + var limit = 1000; // TODO use config + if (!this.group.parent) { + // If not a children no need to load too much + limit = parseInt(limit / fnames_to_fetch.length, 10); + } + + var filter_group = function(record) { + return !(name in record._loaded) && (record.id >= 0); + }; + // TODO pool + [[this.group, filter_group]].forEach(function(e) { + var group = e[0]; + var filter = e[1]; + var idx = this.group.indexOf(this); + if (~idx) { + var length = group.length; + var n = 1; + while (Object.keys(id2record).length && + ((idx - n >= 0) || (idx + n < length)) && + (n < 2 * limit)) { + var record; + if (idx - n >= 0) { + record = group[idx - n]; + if (filter(record)) { + id2record[record.id] = record; + } + } + if (idx + n < length) { + record = group[idx + n]; + if (filter(record)) { + id2record[record.id] = record; + } + } + n++; + } + } + }.bind(this)); + } + for (fname in this.model.fields) { if (!this.model.fields.hasOwnProperty(fname)) { continue; @@ -456,7 +472,7 @@ if (!id2record.hasOwnProperty(id)) { continue; } - record = id2record[id]; + var record = id2record[id]; // TODO exception var value = id2value[id]; if (record && value) { From 61a38d123f253e5f78b587b7d3d2823d563486c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 23 Aug 2013 12:05:58 +0200 Subject: [PATCH 2/8] Missing append of search input in One2Many menu --- src/view.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/view.js b/src/view.js index 0994b250f7..cca9320787 100644 --- a/src/view.js +++ b/src/view.js @@ -1595,6 +1595,7 @@ type: 'input' }); // TODO add completion + this.menu.append(this.wid_text); this.but_add = jQuery('