@ocap/indexdb-elasticsearch 1.18.68 → 1.18.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/db.js +28 -1
- package/package.json +5 -5
package/lib/db.js
CHANGED
|
@@ -28,6 +28,13 @@ const REQUEST_TIMEOUT = 8000;
|
|
|
28
28
|
const MAX_REQUEST_FACTORY_ADDRESS_SIZE = 100;
|
|
29
29
|
const TRACK_TOTAL_HITS = +process.env.TRACK_TOTAL_HITS || 10000;
|
|
30
30
|
|
|
31
|
+
const getMigratedFrom = (account) => {
|
|
32
|
+
if (account.migratedFrom) {
|
|
33
|
+
return Array.isArray(account.migratedFrom) ? account.migratedFrom[0] : account.migratedFrom;
|
|
34
|
+
}
|
|
35
|
+
return '';
|
|
36
|
+
};
|
|
37
|
+
|
|
31
38
|
class ESIndexDB extends BaseIndexDB {
|
|
32
39
|
/**
|
|
33
40
|
* Creates an instance of ESIndexDB.
|
|
@@ -211,10 +218,29 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
211
218
|
return { transactions: items.map((item) => formatTxAfterRead(item)), paging: nextPaging };
|
|
212
219
|
}
|
|
213
220
|
|
|
221
|
+
async getRelatedAddresses(address) {
|
|
222
|
+
let account = await this.account.get(address);
|
|
223
|
+
if (!account) {
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const related = [address];
|
|
228
|
+
while (account && getMigratedFrom(account) && related.length <= 8) {
|
|
229
|
+
related.push(getMigratedFrom(account));
|
|
230
|
+
// eslint-disable-next-line no-await-in-loop
|
|
231
|
+
account = await this.account.get(getMigratedFrom(account));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return related;
|
|
235
|
+
}
|
|
236
|
+
|
|
214
237
|
async listAssets({ ownerAddress, factoryAddress, paging, timeFilter = {} } = {}) {
|
|
215
238
|
const conditions = [];
|
|
216
239
|
if (ownerAddress) {
|
|
217
|
-
|
|
240
|
+
const possibleOwners = await this.getRelatedAddresses(ownerAddress);
|
|
241
|
+
if (possibleOwners.length) {
|
|
242
|
+
conditions.push({ terms: { owner: possibleOwners } });
|
|
243
|
+
}
|
|
218
244
|
}
|
|
219
245
|
if (factoryAddress) {
|
|
220
246
|
conditions.push({ term: { parent: factoryAddress } });
|
|
@@ -228,6 +254,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
228
254
|
return { assets: [], account: null };
|
|
229
255
|
}
|
|
230
256
|
|
|
257
|
+
debug('listAssets query conditions', conditions);
|
|
231
258
|
const pagination = formatPagination({ paging, defaultSortField: 'renaissanceTime' });
|
|
232
259
|
|
|
233
260
|
const [result, account] = await Promise.all([
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/indexdb-elasticsearch",
|
|
3
3
|
"description": "OCAP indexdb adapter that uses elasticsearch as backend",
|
|
4
|
-
"version": "1.18.
|
|
4
|
+
"version": "1.18.70",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/asset-chain/issues",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"test": "jest --forceExit --detectOpenHandles",
|
|
39
39
|
"coverage": "npm run test -- --coverage"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "1f83cffbbb5ac5f34b07cb9302676352ac174286",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@arcblock/did": "1.18.
|
|
43
|
+
"@arcblock/did": "1.18.70",
|
|
44
44
|
"@elastic/elasticsearch": "7.13.0",
|
|
45
|
-
"@ocap/indexdb": "1.18.
|
|
46
|
-
"@ocap/util": "1.18.
|
|
45
|
+
"@ocap/indexdb": "1.18.70",
|
|
46
|
+
"@ocap/util": "1.18.70",
|
|
47
47
|
"axios": "^0.27.2",
|
|
48
48
|
"bn.js": "^5.2.1",
|
|
49
49
|
"debug": "^4.3.4",
|