From a3dd5d2c01ef74e327797bc772ff2a27b4038b51 Mon Sep 17 00:00:00 2001 From: MG60065 Date: Fri, 10 Jun 2022 15:15:34 +0200 Subject: [PATCH 1/2] try to always use native approach to improve faster search when model are fat --- src/js/form-model.js | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/src/js/form-model.js b/src/js/form-model.js index 0db376ad1..db68a51bf 100644 --- a/src/js/form-model.js +++ b/src/js/form-model.js @@ -1561,44 +1561,18 @@ FormModel.prototype.evaluate = function ( } // try native to see if that works... (will not work if the expr contains custom OpenRosa functions) - if ( - tryNative && - typeof doc.evaluate !== 'undefined' && - !OPENROSA.test(expr) - ) { - try { - // console.log( 'trying the blazing fast native XPath Evaluator for', expr, index ); - result = doc.evaluate( - expr, - context, - this.getNsResolver(), - resTypeNum, - null - ); - } catch (e) { - // console.log( '%cWell native XPath evaluation did not work... No worries, worth a shot, the expression probably ' + - // 'contained unknown OpenRosa functions or errors:', expr ); - } - } - - // if that didn't work, try the slow XPathJS evaluator - if (!result) { + try { + // console.log( 'trying the blazing fast native XPath Evaluator for', expr, index ); + result = doc.evaluate( expr, context, this.getNsResolver(), resTypeNum, null ); + } catch { try { - if (typeof doc.jsEvaluate === 'undefined') { + if ( typeof doc.jsEvaluate === 'undefined' ) { this.bindJsEvaluator(); } // console.log( 'trying the slow enketo-xpathjs "openrosa" evaluator for', expr, index ); - result = doc.jsEvaluate( - expr, - context, - this.getNsResolver(), - resTypeNum, - null - ); - } catch (e) { - throw new FormLogicError( - `Could not evaluate: ${expr}, message: ${e.message}` - ); + result = doc.jsEvaluate( expr, context, this.getNsResolver(), resTypeNum, null ); + } catch ( e ) { + throw new FormLogicError( `Could not evaluate: ${expr}, message: ${e.message}` ); } } From 7ae4caacdc8edacb296e9485f8bc86dd813740a7 Mon Sep 17 00:00:00 2001 From: MG60065 Date: Fri, 10 Jun 2022 16:18:18 +0200 Subject: [PATCH 2/2] prettier fix --- src/js/form-model.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/js/form-model.js b/src/js/form-model.js index db68a51bf..53c049b33 100644 --- a/src/js/form-model.js +++ b/src/js/form-model.js @@ -1563,16 +1563,30 @@ FormModel.prototype.evaluate = function ( // try native to see if that works... (will not work if the expr contains custom OpenRosa functions) try { // console.log( 'trying the blazing fast native XPath Evaluator for', expr, index ); - result = doc.evaluate( expr, context, this.getNsResolver(), resTypeNum, null ); + result = doc.evaluate( + expr, + context, + this.getNsResolver(), + resTypeNum, + null + ); } catch { try { if ( typeof doc.jsEvaluate === 'undefined' ) { this.bindJsEvaluator(); } // console.log( 'trying the slow enketo-xpathjs "openrosa" evaluator for', expr, index ); - result = doc.jsEvaluate( expr, context, this.getNsResolver(), resTypeNum, null ); + result = doc.jsEvaluate( + expr, + context, + this.getNsResolver(), + resTypeNum, + null + ); } catch ( e ) { - throw new FormLogicError( `Could not evaluate: ${expr}, message: ${e.message}` ); + throw new FormLogicError( + `Could not evaluate: ${expr}, message: ${e.message}` + ); } }