From 57467048d427324c7cf47545cef29b3f495d2003 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 7 Aug 2023 09:55:18 +0700 Subject: [PATCH 1/8] fix: cw721 activity missing from/to --- src/models/event_attribute.ts | 1 + src/services/cw721/cw721.service.ts | 18 +++++++++++ test/unit/services/cw721/cw721.spec.ts | 42 ++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/models/event_attribute.ts b/src/models/event_attribute.ts index 49200ac98..3836068c7 100644 --- a/src/models/event_attribute.ts +++ b/src/models/event_attribute.ts @@ -90,5 +90,6 @@ export class EventAttribute extends BaseModel { GRANTER: 'granter', GRANTEE: 'grantee', FROM: 'from', + MINTER: 'minter', }; } diff --git a/src/services/cw721/cw721.service.ts b/src/services/cw721/cw721.service.ts index 0a505d672..477f860ee 100644 --- a/src/services/cw721/cw721.service.ts +++ b/src/services/cw721/cw721.service.ts @@ -332,6 +332,24 @@ export default class Cw721HandlerService extends BullableService { cw721_token_id: cw721TokenId, height: cw721Event.height, smart_contract_event_id: cw721Event.smart_contract_event_id, + from: + getAttributeFrom( + cw721Event.attributes, + EventAttribute.ATTRIBUTE_KEY.MINTER + ) || + getAttributeFrom( + cw721Event.attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ), + to: + getAttributeFrom( + cw721Event.attributes, + EventAttribute.ATTRIBUTE_KEY.OWNER + ) || + getAttributeFrom( + cw721Event.attributes, + EventAttribute.ATTRIBUTE_KEY.RECIPIENT + ), }) ) .onConflict(['smart_contract_event_id']) diff --git a/test/unit/services/cw721/cw721.spec.ts b/test/unit/services/cw721/cw721.spec.ts index 3a670e090..7f4e7d11c 100644 --- a/test/unit/services/cw721/cw721.spec.ts +++ b/test/unit/services/cw721/cw721.spec.ts @@ -2,8 +2,16 @@ import { AfterAll, BeforeAll, Describe, Test } from '@jest-decorated/core'; import { ServiceBroker } from 'moleculer'; import { BULL_JOB_NAME } from '../../../../src/common'; import knex from '../../../../src/common/utils/db_connection'; -import { getContractActivities } from '../../../../src/common/utils/smart_contract'; -import { Block, BlockCheckpoint, Transaction } from '../../../../src/models'; +import { + getAttributeFrom, + getContractActivities, +} from '../../../../src/common/utils/smart_contract'; +import { + Block, + BlockCheckpoint, + EventAttribute, + Transaction, +} from '../../../../src/models'; import { Code } from '../../../../src/models/code'; import CW721Contract from '../../../../src/models/cw721_contract'; import CW721Token from '../../../../src/models/cw721_token'; @@ -1296,6 +1304,36 @@ export default class AssetIndexerTest { expect(cw721Activities[0].cw721_token_id).toEqual(1); expect(cw721Activities[1].cw721_token_id).toEqual(0); expect(cw721Activities[2].cw721_token_id).toEqual(2); + expect(cw721Activities[0].from).toEqual( + getAttributeFrom( + mockActivityMsgs[0].attributes, + EventAttribute.ATTRIBUTE_KEY.MINTER + ) + ); + expect(cw721Activities[0].to).toEqual( + getAttributeFrom( + mockActivityMsgs[0].attributes, + EventAttribute.ATTRIBUTE_KEY.OWNER + ) + ); + expect(cw721Activities[1].from).toEqual( + getAttributeFrom( + mockActivityMsgs[1].attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ) + ); + expect(cw721Activities[1].to).toEqual( + getAttributeFrom( + mockActivityMsgs[1].attributes, + EventAttribute.ATTRIBUTE_KEY.RECIPIENT + ) + ); + expect(cw721Activities[2].from).toEqual( + getAttributeFrom( + mockActivityMsgs[2].attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ) + ); } @Test('test handle multi contract events') From 0d6363e2fc575857840294a316138e9491ee2776 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 7 Aug 2023 10:24:05 +0700 Subject: [PATCH 2/8] fix: fill from/to cw721 activity --- src/common/constant.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/constant.ts b/src/common/constant.ts index fcbed0f5f..9299f2788 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -222,6 +222,10 @@ export const SERVICE = { key: 'ReDecodeTx', path: 'v1.ReDecodeTx', }, + FillDataCw721Activity: { + key: 'FillDataCw721Activity', + path: 'v1.FillDataCw721Activity', + }, }, }, }; From 7bd457b6fa2c2bb41c9d5c035eaa5e0726b5ff60 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 7 Aug 2023 16:56:06 +0700 Subject: [PATCH 3/8] fix: fill from/to cw721 activity --- src/common/constant.ts | 7 +- src/models/cw721_tx.ts | 4 +- src/models/smart_contract_event.ts | 2 + .../job/update_data_cw721_activity.service.ts | 102 ++++++++++++++++++ 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/services/job/update_data_cw721_activity.service.ts diff --git a/src/common/constant.ts b/src/common/constant.ts index 9299f2788..a39e8c396 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -66,6 +66,7 @@ export const BULL_JOB_NAME = { REINDEX_CW721_HISTORY: 'reindex:cw721-history', HANDLE_MIGRATE_CONTRACT: 'handle:migrate-contract', JOB_REDECODE_TX: 'job:redecode-tx', + JOB_UPDATE_DATA_CW721_ACTIVITY: 'job:update-data-cw721-activity', }; export const SERVICE = { @@ -222,9 +223,9 @@ export const SERVICE = { key: 'ReDecodeTx', path: 'v1.ReDecodeTx', }, - FillDataCw721Activity: { - key: 'FillDataCw721Activity', - path: 'v1.FillDataCw721Activity', + UpdateDataCw721Activity: { + key: 'UpdateDataCw721Activity', + path: 'v1.UpdateDataCw721Activity', }, }, }, diff --git a/src/models/cw721_tx.ts b/src/models/cw721_tx.ts index fd94f8abe..2db679513 100644 --- a/src/models/cw721_tx.ts +++ b/src/models/cw721_tx.ts @@ -8,7 +8,9 @@ import { SmartContractEvent } from './smart_contract_event'; export default class CW721Activity extends BaseModel { static softDelete = false; - id?: number; + smart_contract_event!: SmartContractEvent; + + id!: number; action?: string; diff --git a/src/models/smart_contract_event.ts b/src/models/smart_contract_event.ts index c7d592c1d..bdf66e80a 100644 --- a/src/models/smart_contract_event.ts +++ b/src/models/smart_contract_event.ts @@ -10,6 +10,8 @@ import { TransactionMessage } from './transaction_message'; export class SmartContractEvent extends BaseModel { [relation: string]: any; + attributes!: SmartContractEventAttribute; + id!: number; smart_contract_id!: number; diff --git a/src/services/job/update_data_cw721_activity.service.ts b/src/services/job/update_data_cw721_activity.service.ts new file mode 100644 index 000000000..7363ac605 --- /dev/null +++ b/src/services/job/update_data_cw721_activity.service.ts @@ -0,0 +1,102 @@ +import { Service } from '@ourparentcenter/moleculer-decorators-extended'; +import { ServiceBroker } from 'moleculer'; +import { getAttributeFrom } from '../../common/utils/smart_contract'; +import CW721Activity from '../../models/cw721_tx'; +import config from '../../../config.json' assert { type: 'json' }; +import BullableService, { QueueHandler } from '../../base/bullable.service'; +import { BULL_JOB_NAME, SERVICE } from '../../common'; +import { EventAttribute } from '../../models'; + +const UPDATE_CW721_ACTIONS = ['mint', 'burn', 'transfer_nft', 'send_nft']; +@Service({ + name: SERVICE.V1.JobService.UpdateDataCw721Activity.key, + version: 1, +}) +export default class JobUpdateDataCw721Activity extends BullableService { + public constructor(public broker: ServiceBroker) { + super(broker); + } + + @QueueHandler({ + queueName: BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + jobName: BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + }) + async updateDataCw721Activity(_payload: { prevId: number }) { + const { prevId } = _payload; + + const handleRecords = await CW721Activity.query() + .withGraphFetched('smart_contract_event.attributes') + .where('cw721_activity.from', null) + .andWhere('cw721_activity.to', null) + .andWhere('cw721_activity.id', '>', prevId) + .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) + .whereNotNull('smart_contract_event_id') + .orderBy('cw721_activity.id') + .limit(config.jobUpdateDataCw721Activity.limitRecordGet); + + if (handleRecords.length > 0) { + const patchQueries: any[] = []; + handleRecords.forEach((record) => { + patchQueries.push( + CW721Activity.query() + .patch({ + from: + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.MINTER + ) || + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ), + to: + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.OWNER + ) || + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.RECIPIENT + ), + }) + .where('id', record.id) + ); + }); + await Promise.all(patchQueries); + await this.createJob( + BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + { + prevId: handleRecords[handleRecords.length - 1].id, + }, + { + removeOnComplete: true, + removeOnFail: { + count: 3, + }, + attempts: config.jobRetryAttempt, + backoff: config.jobRetryBackoff, + } + ); + } + } + + async _start(): Promise { + await this.createJob( + BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, + { + prevId: 0, + }, + { + removeOnComplete: true, + removeOnFail: { + count: 3, + }, + attempts: config.jobRetryAttempt, + backoff: config.jobRetryBackoff, + } + ); + return super._start(); + } +} From 3b59a9803696d43cdcc43ef8913ef498a360c428 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 7 Aug 2023 16:59:14 +0700 Subject: [PATCH 4/8] fix: fill from/to cw721 activity --- ci/config.json.ci | 3 +++ config.json | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ci/config.json.ci b/ci/config.json.ci index 245de74f2..16c3cb48c 100644 --- a/ci/config.json.ci +++ b/ci/config.json.ci @@ -161,5 +161,8 @@ }, "jobRedecodeTx": { "limitRecordGet": 100 + }, + "jobUpdateDataCw721Activity": { + "limitRecordGet": 100 } } diff --git a/config.json b/config.json index cd07b5711..ebf187f0e 100644 --- a/config.json +++ b/config.json @@ -161,5 +161,8 @@ }, "jobRedecodeTx": { "limitRecordGet": 100 + }, + "jobUpdateDataCw721Activity": { + "limitRecordGet": 100 } } From 12306525fa762ddc02aa3cf24d545a674f9f2c12 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 7 Aug 2023 17:13:46 +0700 Subject: [PATCH 5/8] fix: fill from/to cw721 activity --- src/services/cw721/cw721.service.ts | 13 ++++--------- .../job/update_data_cw721_activity.service.ts | 13 ++++--------- test/unit/services/cw721/cw721.spec.ts | 7 +------ 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/services/cw721/cw721.service.ts b/src/services/cw721/cw721.service.ts index 477f860ee..e1facfd0e 100644 --- a/src/services/cw721/cw721.service.ts +++ b/src/services/cw721/cw721.service.ts @@ -332,15 +332,10 @@ export default class Cw721HandlerService extends BullableService { cw721_token_id: cw721TokenId, height: cw721Event.height, smart_contract_event_id: cw721Event.smart_contract_event_id, - from: - getAttributeFrom( - cw721Event.attributes, - EventAttribute.ATTRIBUTE_KEY.MINTER - ) || - getAttributeFrom( - cw721Event.attributes, - EventAttribute.ATTRIBUTE_KEY.SENDER - ), + from: getAttributeFrom( + cw721Event.attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ), to: getAttributeFrom( cw721Event.attributes, diff --git a/src/services/job/update_data_cw721_activity.service.ts b/src/services/job/update_data_cw721_activity.service.ts index 7363ac605..2a5b0922e 100644 --- a/src/services/job/update_data_cw721_activity.service.ts +++ b/src/services/job/update_data_cw721_activity.service.ts @@ -40,15 +40,10 @@ export default class JobUpdateDataCw721Activity extends BullableService { patchQueries.push( CW721Activity.query() .patch({ - from: - getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.MINTER - ) || - getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.SENDER - ), + from: getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ), to: getAttributeFrom( record.smart_contract_event.attributes, diff --git a/test/unit/services/cw721/cw721.spec.ts b/test/unit/services/cw721/cw721.spec.ts index 7f4e7d11c..60c95a64f 100644 --- a/test/unit/services/cw721/cw721.spec.ts +++ b/test/unit/services/cw721/cw721.spec.ts @@ -1304,12 +1304,7 @@ export default class AssetIndexerTest { expect(cw721Activities[0].cw721_token_id).toEqual(1); expect(cw721Activities[1].cw721_token_id).toEqual(0); expect(cw721Activities[2].cw721_token_id).toEqual(2); - expect(cw721Activities[0].from).toEqual( - getAttributeFrom( - mockActivityMsgs[0].attributes, - EventAttribute.ATTRIBUTE_KEY.MINTER - ) - ); + expect(cw721Activities[0].from).toEqual(null); expect(cw721Activities[0].to).toEqual( getAttributeFrom( mockActivityMsgs[0].attributes, From fd56dd47f4b8ea1728ff07fed2cb6db8a2f1f1a4 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Tue, 8 Aug 2023 14:37:08 +0700 Subject: [PATCH 6/8] refactor: code --- ...230808072704_update_data_cw721_activity.ts | 51 ++++++++++ src/common/constant.ts | 5 - .../job/update_data_cw721_activity.service.ts | 97 ------------------- 3 files changed, 51 insertions(+), 102 deletions(-) create mode 100644 migrations/20230808072704_update_data_cw721_activity.ts delete mode 100644 src/services/job/update_data_cw721_activity.service.ts diff --git a/migrations/20230808072704_update_data_cw721_activity.ts b/migrations/20230808072704_update_data_cw721_activity.ts new file mode 100644 index 000000000..dffd8b7b7 --- /dev/null +++ b/migrations/20230808072704_update_data_cw721_activity.ts @@ -0,0 +1,51 @@ +import { Knex } from 'knex'; +import config from '../config.json' assert { type: 'json' }; +import CW721Activity from '../src/models/cw721_tx'; +import { getAttributeFrom } from '../src/common/utils/smart_contract'; +import { EventAttribute } from '../src/models'; +const UPDATE_CW721_ACTIONS = ['mint', 'burn', 'transfer_nft', 'send_nft']; +export async function up(knex: Knex): Promise { + let prevId = 0; + while (true) { + const handleRecords = await CW721Activity.query() + .withGraphFetched('smart_contract_event.attributes') + .where('cw721_activity.from', null) + .andWhere('cw721_activity.to', null) + .andWhere('cw721_activity.id', '>', prevId) + .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) + .whereNotNull('smart_contract_event_id') + .orderBy('cw721_activity.id') + .limit(config.jobUpdateDataCw721Activity.limitRecordGet); + + if (handleRecords.length > 0) { + const patchQueries: any[] = []; + handleRecords.forEach((record) => { + patchQueries.push( + CW721Activity.query() + .patch({ + from: getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.SENDER + ), + to: + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.OWNER + ) || + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.RECIPIENT + ), + }) + .where('id', record.id) + ); + }); + await Promise.all(patchQueries); + prevId = handleRecords[handleRecords.length - 1].id; + } else { + break; + } + } +} + +export async function down(knex: Knex): Promise {} diff --git a/src/common/constant.ts b/src/common/constant.ts index a39e8c396..fcbed0f5f 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -66,7 +66,6 @@ export const BULL_JOB_NAME = { REINDEX_CW721_HISTORY: 'reindex:cw721-history', HANDLE_MIGRATE_CONTRACT: 'handle:migrate-contract', JOB_REDECODE_TX: 'job:redecode-tx', - JOB_UPDATE_DATA_CW721_ACTIVITY: 'job:update-data-cw721-activity', }; export const SERVICE = { @@ -223,10 +222,6 @@ export const SERVICE = { key: 'ReDecodeTx', path: 'v1.ReDecodeTx', }, - UpdateDataCw721Activity: { - key: 'UpdateDataCw721Activity', - path: 'v1.UpdateDataCw721Activity', - }, }, }, }; diff --git a/src/services/job/update_data_cw721_activity.service.ts b/src/services/job/update_data_cw721_activity.service.ts deleted file mode 100644 index 2a5b0922e..000000000 --- a/src/services/job/update_data_cw721_activity.service.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Service } from '@ourparentcenter/moleculer-decorators-extended'; -import { ServiceBroker } from 'moleculer'; -import { getAttributeFrom } from '../../common/utils/smart_contract'; -import CW721Activity from '../../models/cw721_tx'; -import config from '../../../config.json' assert { type: 'json' }; -import BullableService, { QueueHandler } from '../../base/bullable.service'; -import { BULL_JOB_NAME, SERVICE } from '../../common'; -import { EventAttribute } from '../../models'; - -const UPDATE_CW721_ACTIONS = ['mint', 'burn', 'transfer_nft', 'send_nft']; -@Service({ - name: SERVICE.V1.JobService.UpdateDataCw721Activity.key, - version: 1, -}) -export default class JobUpdateDataCw721Activity extends BullableService { - public constructor(public broker: ServiceBroker) { - super(broker); - } - - @QueueHandler({ - queueName: BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - jobName: BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - }) - async updateDataCw721Activity(_payload: { prevId: number }) { - const { prevId } = _payload; - - const handleRecords = await CW721Activity.query() - .withGraphFetched('smart_contract_event.attributes') - .where('cw721_activity.from', null) - .andWhere('cw721_activity.to', null) - .andWhere('cw721_activity.id', '>', prevId) - .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) - .whereNotNull('smart_contract_event_id') - .orderBy('cw721_activity.id') - .limit(config.jobUpdateDataCw721Activity.limitRecordGet); - - if (handleRecords.length > 0) { - const patchQueries: any[] = []; - handleRecords.forEach((record) => { - patchQueries.push( - CW721Activity.query() - .patch({ - from: getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.SENDER - ), - to: - getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.OWNER - ) || - getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.RECIPIENT - ), - }) - .where('id', record.id) - ); - }); - await Promise.all(patchQueries); - await this.createJob( - BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - { - prevId: handleRecords[handleRecords.length - 1].id, - }, - { - removeOnComplete: true, - removeOnFail: { - count: 3, - }, - attempts: config.jobRetryAttempt, - backoff: config.jobRetryBackoff, - } - ); - } - } - - async _start(): Promise { - await this.createJob( - BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - BULL_JOB_NAME.JOB_UPDATE_DATA_CW721_ACTIVITY, - { - prevId: 0, - }, - { - removeOnComplete: true, - removeOnFail: { - count: 3, - }, - attempts: config.jobRetryAttempt, - backoff: config.jobRetryBackoff, - } - ); - return super._start(); - } -} From 1a98651607fc67d169fb6813d49cb9a94f5d92f0 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Tue, 8 Aug 2023 15:36:06 +0700 Subject: [PATCH 7/8] fix: code --- ...230808072704_update_data_cw721_activity.ts | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/migrations/20230808072704_update_data_cw721_activity.ts b/migrations/20230808072704_update_data_cw721_activity.ts index dffd8b7b7..81eda430e 100644 --- a/migrations/20230808072704_update_data_cw721_activity.ts +++ b/migrations/20230808072704_update_data_cw721_activity.ts @@ -5,47 +5,51 @@ import { getAttributeFrom } from '../src/common/utils/smart_contract'; import { EventAttribute } from '../src/models'; const UPDATE_CW721_ACTIONS = ['mint', 'burn', 'transfer_nft', 'send_nft']; export async function up(knex: Knex): Promise { - let prevId = 0; - while (true) { - const handleRecords = await CW721Activity.query() - .withGraphFetched('smart_contract_event.attributes') - .where('cw721_activity.from', null) - .andWhere('cw721_activity.to', null) - .andWhere('cw721_activity.id', '>', prevId) - .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) - .whereNotNull('smart_contract_event_id') - .orderBy('cw721_activity.id') - .limit(config.jobUpdateDataCw721Activity.limitRecordGet); + await knex.transaction(async (trx) => { + let prevId = 0; + while (true) { + const handleRecords = await CW721Activity.query() + .withGraphFetched('smart_contract_event.attributes') + .where('cw721_activity.from', null) + .andWhere('cw721_activity.to', null) + .andWhere('cw721_activity.id', '>', prevId) + .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) + .whereNotNull('smart_contract_event_id') + .orderBy('cw721_activity.id') + .limit(config.jobUpdateDataCw721Activity.limitRecordGet) + .transacting(trx); - if (handleRecords.length > 0) { - const patchQueries: any[] = []; - handleRecords.forEach((record) => { - patchQueries.push( - CW721Activity.query() - .patch({ - from: getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.SENDER - ), - to: - getAttributeFrom( + if (handleRecords.length > 0) { + const patchQueries: any[] = []; + handleRecords.forEach((record) => { + patchQueries.push( + CW721Activity.query() + .patch({ + from: getAttributeFrom( record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.OWNER - ) || - getAttributeFrom( - record.smart_contract_event.attributes, - EventAttribute.ATTRIBUTE_KEY.RECIPIENT + EventAttribute.ATTRIBUTE_KEY.SENDER ), - }) - .where('id', record.id) - ); - }); - await Promise.all(patchQueries); - prevId = handleRecords[handleRecords.length - 1].id; - } else { - break; + to: + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.OWNER + ) || + getAttributeFrom( + record.smart_contract_event.attributes, + EventAttribute.ATTRIBUTE_KEY.RECIPIENT + ), + }) + .where('id', record.id) + .transacting(trx) + ); + }); + await Promise.all(patchQueries); + prevId = handleRecords[handleRecords.length - 1].id; + } else { + break; + } } - } + }); } export async function down(knex: Knex): Promise {} From ae40af2ca7e7ac6ccc05fa8e41ea3e8ca236bab6 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Wed, 9 Aug 2023 14:24:13 +0700 Subject: [PATCH 8/8] refactor: code --- ci/config.json.ci | 3 --- config.json | 3 --- migrations/20230808072704_update_data_cw721_activity.ts | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/ci/config.json.ci b/ci/config.json.ci index 16c3cb48c..245de74f2 100644 --- a/ci/config.json.ci +++ b/ci/config.json.ci @@ -161,8 +161,5 @@ }, "jobRedecodeTx": { "limitRecordGet": 100 - }, - "jobUpdateDataCw721Activity": { - "limitRecordGet": 100 } } diff --git a/config.json b/config.json index ebf187f0e..cd07b5711 100644 --- a/config.json +++ b/config.json @@ -161,8 +161,5 @@ }, "jobRedecodeTx": { "limitRecordGet": 100 - }, - "jobUpdateDataCw721Activity": { - "limitRecordGet": 100 } } diff --git a/migrations/20230808072704_update_data_cw721_activity.ts b/migrations/20230808072704_update_data_cw721_activity.ts index 81eda430e..c78964cef 100644 --- a/migrations/20230808072704_update_data_cw721_activity.ts +++ b/migrations/20230808072704_update_data_cw721_activity.ts @@ -16,7 +16,7 @@ export async function up(knex: Knex): Promise { .whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) .whereNotNull('smart_contract_event_id') .orderBy('cw721_activity.id') - .limit(config.jobUpdateDataCw721Activity.limitRecordGet) + .limit(100) .transacting(trx); if (handleRecords.length > 0) {