diff --git a/package-lock.json b/package-lock.json index c7a79e8f2..e2a62b2d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12926,7 +12926,7 @@ }, "packages/runtime": { "name": "@nmshd/runtime", - "version": "3.5.0", + "version": "3.5.1", "license": "MIT", "dependencies": { "@js-soft/docdb-querytranslator": "^1.1.2", @@ -12936,7 +12936,7 @@ "@nmshd/consumption": "3.9.2", "@nmshd/content": "2.8.4", "@nmshd/crypto": "2.0.5", - "@nmshd/transport": "2.2.1", + "@nmshd/transport": "2.2.2", "ajv": "^8.12.0", "ajv-errors": "^3.0.0", "ajv-formats": "^2.1.1", @@ -12961,7 +12961,7 @@ }, "packages/transport": { "name": "@nmshd/transport", - "version": "2.2.1", + "version": "2.2.2", "license": "MIT", "dependencies": { "@js-soft/docdb-access-abstractions": "1.0.3", @@ -14056,7 +14056,7 @@ "@nmshd/consumption": "3.9.2", "@nmshd/content": "2.8.4", "@nmshd/crypto": "2.0.5", - "@nmshd/transport": "2.2.1", + "@nmshd/transport": "2.2.2", "@types/json-stringify-safe": "^5.0.3", "@types/lodash": "^4.14.202", "@types/luxon": "^3.4.2", diff --git a/packages/runtime/package.json b/packages/runtime/package.json index c9ec8129c..79d06d2dc 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@nmshd/runtime", - "version": "3.5.0", + "version": "3.5.1", "description": "The enmeshed client runtime.", "homepage": "https://enmeshed.eu", "repository": { @@ -67,7 +67,7 @@ "@nmshd/consumption": "3.9.2", "@nmshd/content": "2.8.4", "@nmshd/crypto": "2.0.5", - "@nmshd/transport": "2.2.1", + "@nmshd/transport": "2.2.2", "ajv": "^8.12.0", "ajv-errors": "^3.0.0", "ajv-formats": "^2.1.1", diff --git a/packages/transport/package.json b/packages/transport/package.json index 26fa727f0..b8ad4e1ef 100644 --- a/packages/transport/package.json +++ b/packages/transport/package.json @@ -1,6 +1,6 @@ { "name": "@nmshd/transport", - "version": "2.2.1", + "version": "2.2.2", "description": "The transport library handles backbone communication and content encryption.", "homepage": "https://enmeshed.eu", "repository": { diff --git a/packages/transport/src/modules/relationships/RelationshipsController.ts b/packages/transport/src/modules/relationships/RelationshipsController.ts index a7c10f04e..a0dc60922 100644 --- a/packages/transport/src/modules/relationships/RelationshipsController.ts +++ b/packages/transport/src/modules/relationships/RelationshipsController.ts @@ -99,14 +99,18 @@ export class RelationshipsController extends TransportController { } public async getRelationshipToIdentity(address: CoreAddress, status?: RelationshipStatus): Promise { - const query: any = { - [`${nameof((r) => r.peer)}.${nameof((r) => r.address)}`]: address.toString() - }; - if (status) { - query[`${nameof((r) => r.status)}`] = status; + const query: any = { peerAddress: address.toString() }; + if (status) query[`${nameof((r) => r.status)}`] = status; + let relationshipDoc = await this.relationships.findOne(query); + + if (!relationshipDoc) { + // If we don't find the relationship by peerAddress, we have to check again by peer.address + // as the Relationship could have been created before the peerAddress was introduced + const query = { [`${nameof((r) => r.peer)}.${nameof((r) => r.address)}`]: address.toString() }; + if (status) query[`${nameof((r) => r.status)}`] = status; + relationshipDoc = await this.relationships.findOne(query); } - const relationshipDoc = await this.relationships.findOne(query); if (!relationshipDoc) { return; } diff --git a/packages/transport/src/modules/relationships/local/Relationship.ts b/packages/transport/src/modules/relationships/local/Relationship.ts index 6ab0337bb..65d4fffb4 100644 --- a/packages/transport/src/modules/relationships/local/Relationship.ts +++ b/packages/transport/src/modules/relationships/local/Relationship.ts @@ -61,6 +61,17 @@ export class Relationship extends CoreSynchronizable implements IRelationship { @serialize() public metadataModifiedAt?: CoreDate; + public override toJSON(verbose?: boolean | undefined, serializeAsString?: boolean | undefined): Object { + const json = super.toJSON(verbose, serializeAsString) as any; + + // Adds flattened peerAddress and templateId to the JSON stored in the database. + // This helps us to boost the performance of database queries that include these fields. + json.peerAddress = this.peer.address.toString(); + json.templateId = this.cache?.template.id.toString(); + + return json; + } + public static fromRequestSent(id: CoreId, template: IRelationshipTemplate, peer: IIdentity, creationChange: IRelationshipChange, relationshipSecretId: CoreId): Relationship { const cache = CachedRelationship.from({ changes: [creationChange],