()
| 119 | } |
| 120 | |
| 121 | makeStoreSchema(): { |
| 122 | dimensions: DataStoreDimensionDefine[]; |
| 123 | hash: string |
| 124 | } { |
| 125 | const dimCount = this._fullDimCount; |
| 126 | const willRetrieveDataByName = shouldRetrieveDataByName(this.source); |
| 127 | const makeHashStrict = !shouldOmitUnusedDimensions(dimCount); |
| 128 | |
| 129 | // If source don't have dimensions or series don't omit unsed dimensions. |
| 130 | // Generate from seriesDimList directly |
| 131 | let dimHash = ''; |
| 132 | const dims: DataStoreDimensionDefine[] = []; |
| 133 | |
| 134 | for (let fullDimIdx = 0, seriesDimIdx = 0; fullDimIdx < dimCount; fullDimIdx++) { |
| 135 | let property: string; |
| 136 | let type: DimensionType; |
| 137 | let ordinalMeta: OrdinalMeta; |
| 138 | |
| 139 | const seriesDimDef = this.dimensions[seriesDimIdx]; |
| 140 | // The list has been sorted by `storeDimIndex` asc. |
| 141 | if (seriesDimDef && seriesDimDef.storeDimIndex === fullDimIdx) { |
| 142 | property = willRetrieveDataByName ? seriesDimDef.name : null; |
| 143 | type = seriesDimDef.type; |
| 144 | ordinalMeta = seriesDimDef.ordinalMeta; |
| 145 | |
| 146 | seriesDimIdx++; |
| 147 | } |
| 148 | else { |
| 149 | const sourceDimDef = this.getSourceDimension(fullDimIdx); |
| 150 | if (sourceDimDef) { |
| 151 | property = willRetrieveDataByName ? sourceDimDef.name : null; |
| 152 | type = sourceDimDef.type; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | dims.push({ property, type, ordinalMeta }); |
| 157 | |
| 158 | // If retrieving data by index, |
| 159 | // use <index, type, ordinalMeta> to determine whether data can be shared. |
| 160 | // (Because in this case there might be no dimension name defined in dataset, but indices always exists). |
| 161 | // (Indices are always 0, 1, 2, ..., so we can ignore them to shorten the hash). |
| 162 | // Otherwise if retrieving data by property name (like `data: [{aa: 123, bb: 765}, ...]`), |
| 163 | // use <property, type, ordinalMeta> in hash. |
| 164 | if (willRetrieveDataByName |
| 165 | && property != null |
| 166 | // For data stack, we have make sure each series has its own dim on this store. |
| 167 | // So we do not add property to hash to make sure they can share this store. |
| 168 | && (!seriesDimDef || !seriesDimDef.isCalculationCoord) |
| 169 | ) { |
| 170 | dimHash += (makeHashStrict |
| 171 | // Use escape character '`' in case that property name contains '$'. |
| 172 | ? property.replace(/\`/g, '`1').replace(/\$/g, '`2') |
| 173 | // For better performance, when there are large dimensions, tolerant this defects that hardly meet. |
| 174 | : property |
| 175 | ); |
| 176 | } |
| 177 | dimHash += '$'; |
| 178 | dimHash += dimTypeShort[type] || 'f'; |
no test coverage detected