diff --git a/sdk/ext/CloudData.class.js b/sdk/ext/CloudData.class.js index 6a1d26c0f9e05cbdfce2238e490c43ef4c1ee70a..0498d74caa217707fb23e0c71f9f57d03ba8355b 100644 --- a/sdk/ext/CloudData.class.js +++ b/sdk/ext/CloudData.class.js @@ -90,49 +90,25 @@ export default class CloudData { // console.time('find dataMap.get' + this.constructor.name) res = this.dataMap.get(mapKey) // console.timeEnd('find dataMap.get' + this.constructor.name) - return res } else { console.log('注意:此次查找未走索引',param,this.indexKey,this.constructor.name) } - } + } - console.time('find-no-index-' + this.constructor.name) - // 默认查找条件为_id - if(typeof param == 'string'){ - res = dataList.find(item => item._id == param) - }else if(typeof param == 'object'){ - // console.log('param',param) - function isEq(a, b) { - if (Array.isArray(a) || Array.isArray(b)) { - console.error('不支持数组比较') - return a === b; - } - let result = true; - for (let key in b) { - const valueA = a[key]; - const valueB = b[key]; - if (typeof valueB === 'object' - && valueB !== null - && typeof valueA === 'object' - && valueA !== null - ) { - return isEq(valueA, valueB); - } - result = valueA === valueB; - if (!result) { - break; - } - } - return result; + if(!res) { + console.time('find-no-index-' + this.constructor.name) + // 默认查找条件为_id + if(typeof param == 'string'){ + res = dataList.find(item => item._id == param) + }else if(typeof param == 'object'){ + // console.log('param',param) + res = dataList.find(item => isEq(item,param)) + }else{ + throw new Error('错误的查找条件') } - res = dataList.find(item => isEq(item,param)) - }else{ - throw new Error('错误的查找条件') - } - if(this.__afterFind){ - res = this.__afterFind({param,res}) + console.timeEnd('find-no-index-' + this.constructor.name) } - console.timeEnd('find-no-index-' + this.constructor.name) + this.__afterFind?.({param,res}) return res } /** @description 查询数据,先从本地查找,如果没有则从云端拉取 @@ -327,4 +303,28 @@ function convertObjToString(obj) { } recursiveConvert(obj, ''); return result; +} + +function isEq(a, b) { + if (Array.isArray(a) || Array.isArray(b)) { + console.error('不支持数组比较') + return a === b; + } + let result = true; + for (let key in b) { + const valueA = a[key]; + const valueB = b[key]; + if (typeof valueB === 'object' + && valueB !== null + && typeof valueA === 'object' + && valueA !== null + ) { + return isEq(valueA, valueB); + } + result = valueA === valueB; + if (!result) { + break; + } + } + return result; } \ No newline at end of file