diff --git a/package-lock.json b/package-lock.json index 1690bab2ef..9272218fc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "6.3.0+hotfix.1", + "version": "6.3.0+hotfix.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "6.3.0+hotfix.1", + "version": "6.3.0+hotfix.2", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 829f671121..2d3f748c92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "6.3.0+hotfix.1", + "version": "6.3.0+hotfix.2", "description": "OTNode V6", "main": "index.js", "type": "module", diff --git a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js index 1782490af6..c95e8a65b5 100644 --- a/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js +++ b/src/commands/common/get-latest-service-agreement/blockchain-get-latest-service-agreement.js @@ -45,6 +45,9 @@ class BlockchainGetLatestServiceAgreement extends Command { if (result) { // eslint-disable-next-line no-param-reassign command.data[result.contract] = result.lastProcessedTokenId; + this.logger.debug( + `Get latest service agreement: updating last processed token id: ${result.lastProcessedTokenId} for blockchain ${blockchain}`, + ); } }); @@ -131,7 +134,7 @@ class BlockchainGetLatestServiceAgreement extends Command { } return { contract, - lastProcessedTokenId: latestDbTokenId, + lastProcessedTokenId: latestBlockchainTokenId, }; } @@ -142,6 +145,12 @@ class BlockchainGetLatestServiceAgreement extends Command { hashFunctionId = CONTENT_ASSET_HASH_FUNCTION_ID, ) { try { + if (await this.repositoryModuleManager.serviceAgreementExists(blockchain, tokenId)) { + this.logger.debug( + `Get latest service agreement: data exists in repository for token id: ${tokenId} on blockchain: ${blockchain}`, + ); + return; + } this.logger.debug( `Get latest service agreement: Getting agreement data for token id: ${tokenId} on blockchain: ${blockchain}`, ); diff --git a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js index 19ffb462a3..062a6876e3 100644 --- a/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js +++ b/src/modules/repository/implementation/sequelize/repositories/service-agreement-repository.js @@ -83,6 +83,16 @@ class ServiceAgreementRepository { ); } + async serviceAgreementExists(blockchainId, tokenId) { + const agreementRecord = await this.model.findOne({ + where: { + blockchainId, + tokenId, + }, + }); + return !!agreementRecord; + } + async bulkCreateServiceAgreementRecords(serviceAgreements) { return this.model.bulkCreate(serviceAgreements, { ignoreDuplicates: true, diff --git a/src/modules/repository/repository-module-manager.js b/src/modules/repository/repository-module-manager.js index e39a44b81b..9aefcb5535 100644 --- a/src/modules/repository/repository-module-manager.js +++ b/src/modules/repository/repository-module-manager.js @@ -344,6 +344,15 @@ class RepositoryModuleManager extends BaseModuleManager { } } + async serviceAgreementExists(blockchain, tokenId) { + if (this.initialized) { + return this.getRepository('service_agreement').serviceAgreementExists( + blockchain, + tokenId, + ); + } + } + async bulkCreateServiceAgreementRecords(records) { if (this.initialized) { return this.getRepository('service_agreement').bulkCreateServiceAgreementRecords(