Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/incremental document sync #674

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
65ca95c
feat: add last did sync entity
JGiter Nov 6, 2024
aa7287a
feat: incremental document sync
JGiter Nov 6, 2024
aa0c6fd
fix: use did update job type
JGiter Nov 6, 2024
dbad1a7
chore: sync doc comment
JGiter Nov 6, 2024
fc67cfc
fix: did service spec
JGiter Nov 6, 2024
2aad708
refactor: rename latest did sync
JGiter Nov 6, 2024
717fb36
refactor: add changed identities in interval
JGiter Nov 7, 2024
10544f2
feat: add did sync status entity
JGiter Nov 8, 2024
ed07d8b
feat: set document sync status
JGiter Nov 8, 2024
b07d0bb
test: did service
JGiter Nov 8, 2024
df16649
feat: inject did sync status
JGiter Nov 8, 2024
7b61929
refactor: mark stale documents
JGiter Nov 8, 2024
464c866
fix: dont duplicate update doc job
JGiter Nov 8, 2024
27d5e7a
fix: did_status_entity.document
JGiter Nov 12, 2024
91a6041
fix: update doc transactionally
JGiter Nov 12, 2024
2ae001c
fix: did sync status migration
JGiter Nov 12, 2024
8cd5a29
test: did service
JGiter Nov 12, 2024
5348618
refactor: query changed did on db
JGiter Nov 19, 2024
ee3cb8a
feat: limit max synced docs
JGiter Nov 19, 2024
ed78e5a
fix: fetch sync status with doc
JGiter Nov 19, 2024
ff5affb
feat: catch failed sync
JGiter Nov 19, 2024
dd41ef1
docs: incremental sync
JGiter Nov 19, 2024
f4d81d4
feat: migrate did sync status
JGiter Nov 19, 2024
b74d350
fix: did sync status column names
JGiter Nov 19, 2024
6ca5bbd
fix: synced block
JGiter Nov 20, 2024
6a4e4da
fix: use logger
JGiter Nov 20, 2024
38e61a4
fix: mark if changed dids not empty
JGiter Nov 20, 2024
377faa1
fix: commit synced doc tx
JGiter Nov 20, 2024
0140407
fix: save status on new did
JGiter Nov 20, 2024
4de22a0
test: did service
JGiter Nov 20, 2024
1443869
fix: save new sync status
JGiter Nov 20, 2024
70db7bb
refactor: upsert status on did update
JGiter Nov 21, 2024
379730d
feat: create status if not found in sync
JGiter Nov 21, 2024
215965e
chore: discard tx mark stale
JGiter Nov 21, 2024
258ae85
chore: log failed sync
JGiter Nov 21, 2024
1391c02
test: did service
JGiter Nov 21, 2024
8bfd1e9
docs: getChangedIdentities
JGiter Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Class: DidSyncStatusEntity

[modules/did/didSyncStatus.entity](../modules/modules_did_didSyncStatus_entity.md).DidSyncStatusEntity

## Table of contents

### Constructors

- [constructor](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md#constructor)

### Properties

- [createdDate](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md#createddate)
- [document](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md#document)
- [id](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md#id)
- [status](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md#status)

## Constructors

### constructor

• **new DidSyncStatusEntity**()

## Properties

### createdDate

• **createdDate**: `Date`

___

### document

• **document**: [`DIDDocumentEntity`](modules_did_did_entity.DIDDocumentEntity.md)

___

### id

• **id**: `number`

___

### status

• **status**: [`DidSyncStatus`](../enums/modules_did_did_types.DidSyncStatus.md)
14 changes: 7 additions & 7 deletions docs/api/classes/modules_did_did_processor.DIDProcessor.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

### OnQueueWaiting

▸ **OnQueueWaiting**(`job`): `Promise`<`void`\>
▸ **OnQueueWaiting**(`jobId`): `Promise`<`void`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `jobId` | `number` |

#### Returns

Expand All @@ -59,7 +59,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |

#### Returns

Expand Down Expand Up @@ -91,7 +91,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |

#### Returns

Expand All @@ -107,7 +107,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |

#### Returns

Expand All @@ -123,7 +123,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`string`\> |
| `job` | `Job`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |

#### Returns

Expand All @@ -139,7 +139,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`string`\> |
| `job` | `Job`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |

#### Returns

Expand Down
7 changes: 5 additions & 2 deletions docs/api/classes/modules_did_did_service.DIDService.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

### constructor

• **new DIDService**(`config`, `schedulerRegistry`, `httpService`, `didQueue`, `logger`, `didRepository`, `provider`, `sentryTracingService`, `registrySettings`, `ipfsService`)
• **new DIDService**(`config`, `schedulerRegistry`, `httpService`, `didQueue`, `logger`, `didRepository`, `provider`, `sentryTracingService`, `registrySettings`, `ipfsService`, `latestDidSyncRepository`, `didSyncStatusRepository`, `dataSource`)

#### Parameters

Expand All @@ -37,13 +37,16 @@
| `config` | `ConfigService`<`Record`<`string`, `unknown`\>, ``false``\> |
| `schedulerRegistry` | `SchedulerRegistry` |
| `httpService` | `HttpService` |
| `didQueue` | `Queue`<`string`\> |
| `didQueue` | `Queue`<[`UpdateDocumentJobData`](../modules/modules_did_did_types.md#updatedocumentjobdata)\> |
| `logger` | [`Logger`](modules_logger_logger_service.Logger.md) |
| `didRepository` | `Repository`<[`DIDDocumentEntity`](modules_did_did_entity.DIDDocumentEntity.md)\> |
| `provider` | [`Provider`](common_provider.Provider.md) |
| `sentryTracingService` | [`SentryTracingService`](modules_sentry_sentry_tracing_service.SentryTracingService.md) |
| `registrySettings` | `RegistrySettings` |
| `ipfsService` | [`IPFSService`](modules_ipfs_ipfs_service.IPFSService.md) |
| `latestDidSyncRepository` | `Repository`<[`LatestDidSync`](modules_did_latestDidSync_entity.LatestDidSync.md)\> |
| `didSyncStatusRepository` | `Repository`<[`DidSyncStatusEntity`](modules_did_didSyncStatus_entity.DidSyncStatusEntity.md)\> |
| `dataSource` | `DataSource` |

## Methods

Expand Down
32 changes: 32 additions & 0 deletions docs/api/classes/modules_did_latestDidSync_entity.LatestDidSync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Class: LatestDidSync

[modules/did/latestDidSync.entity](../modules/modules_did_latestDidSync_entity.md).LatestDidSync

## Table of contents

### Constructors

- [constructor](modules_did_latestDidSync_entity.LatestDidSync.md#constructor)

### Properties

- [block](modules_did_latestDidSync_entity.LatestDidSync.md#block)
- [createdDate](modules_did_latestDidSync_entity.LatestDidSync.md#createddate)

## Constructors

### constructor

• **new LatestDidSync**()

## Properties

### block

• **block**: `number`

___

### createdDate

• **createdDate**: `Date`
8 changes: 4 additions & 4 deletions docs/api/classes/modules_ipfs_pin_processor.PinProcessor.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

### OnQueueWaiting

▸ **OnQueueWaiting**(`job`): `Promise`<`void`\>
▸ **OnQueueWaiting**(`jobId`): `Promise`<`void`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `jobId` | `number` |

#### Returns

Expand Down Expand Up @@ -72,7 +72,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> |
| `err` | `Error` |

#### Returns
Expand All @@ -89,7 +89,7 @@ ___

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> |

#### Returns

Expand Down
22 changes: 22 additions & 0 deletions docs/api/enums/modules_did_did_types.DidSyncStatus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Enumeration: DidSyncStatus

[modules/did/did.types](../modules/modules_did_did_types.md).DidSyncStatus

## Table of contents

### Enumeration Members

- [Stale](modules_did_did_types.DidSyncStatus.md#stale)
- [Synced](modules_did_did_types.DidSyncStatus.md#synced)

## Enumeration Members

### Stale

• **Stale** = ``1``

___

### Synced

• **Synced** = ``0``
2 changes: 2 additions & 0 deletions docs/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
- [modules/did/did.resolver](modules/modules_did_did_resolver.md)
- [modules/did/did.service](modules/modules_did_did_service.md)
- [modules/did/did.types](modules/modules_did_did_types.md)
- [modules/did/didSyncStatus.entity](modules/modules_did_didSyncStatus_entity.md)
- [modules/did/latestDidSync.entity](modules/modules_did_latestDidSync_entity.md)
- [modules/ens/ens.module](modules/modules_ens_ens_module.md)
- [modules/ens/ens.service](modules/modules_ens_ens_service.md)
- [modules/interceptors/interceptors.module](modules/modules_interceptors_interceptors_module.md)
Expand Down
7 changes: 7 additions & 0 deletions docs/api/modules/modules_did_didSyncStatus_entity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Module: modules/did/didSyncStatus.entity

## Table of contents

### Classes

- [DidSyncStatusEntity](../classes/modules_did_didSyncStatus_entity.DidSyncStatusEntity.md)
20 changes: 20 additions & 0 deletions docs/api/modules/modules_did_did_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

## Table of contents

### Enumerations

- [DidSyncStatus](../enums/modules_did_did_types.DidSyncStatus.md)

### Classes

- [DID](../classes/modules_did_did_types.DID.md)

### Type Aliases

- [UpdateDocumentJobData](modules_did_did_types.md#updatedocumentjobdata)

### Variables

- [ADD\_DID\_DOC\_JOB\_NAME](modules_did_did_types.md#add_did_doc_job_name)
Expand All @@ -17,6 +25,18 @@

- [getDIDFromAddress](modules_did_did_types.md#getdidfromaddress)

## Type Aliases

### UpdateDocumentJobData

Ƭ **UpdateDocumentJobData**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `did` | `string` |

## Variables

### ADD\_DID\_DOC\_JOB\_NAME
Expand Down
7 changes: 7 additions & 0 deletions docs/api/modules/modules_did_latestDidSync_entity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Module: modules/did/latestDidSync.entity

## Table of contents

### Classes

- [LatestDidSync](../classes/modules_did_latestDidSync_entity.LatestDidSync.md)
15 changes: 15 additions & 0 deletions src/migrations/1730905681141-LatestDidSync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class LatestDidSync1730905681141 implements MigrationInterface {
name = 'LatestDidSync1730905681141';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "latest_did_sync" ("block" integer NOT NULL, "createdDate" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_9e615062cb9a1c6b45598e74eae" PRIMARY KEY ("block"))`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "latest_did_sync"`);
}
}
30 changes: 30 additions & 0 deletions src/migrations/1732050720611-AddDidSyncStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddDidSyncStatus1732050720611 implements MigrationInterface {
name = 'AddDidSyncStatus1732050720611';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."did_sync_status_entity_status_enum" AS ENUM('0', '1')`
);
await queryRunner.query(
`CREATE TABLE "did_sync_status_entity" ("id" SERIAL NOT NULL, "status" "public"."did_sync_status_entity_status_enum" NOT NULL DEFAULT '0', "created_date" TIMESTAMP NOT NULL DEFAULT now(), "document_id" character varying NOT NULL, CONSTRAINT "REL_100b8d489b25f9c448ec03e482" UNIQUE ("document_id"), CONSTRAINT "PK_e7f58d90249f1f87ddc5132cb11" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`ALTER TABLE "did_sync_status_entity" ADD CONSTRAINT "FK_100b8d489b25f9c448ec03e482d" FOREIGN KEY ("document_id") REFERENCES "did_document_entity"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
);
await queryRunner.query(
`INSERT INTO did_sync_status_entity (document_id) SELECT id FROM did_document_entity`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "did_sync_status_entity" DROP CONSTRAINT "FK_100b8d489b25f9c448ec03e482d"`
);
await queryRunner.query(`DROP TABLE "did_sync_status_entity"`);
await queryRunner.query(
`DROP TYPE "public"."did_sync_status_entity_status_enum"`
);
}
}
8 changes: 7 additions & 1 deletion src/modules/did/did.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Methods } from '@ew-did-registry/did';
import { Provider } from '../../common/provider';
import { DIDController } from './did.controller';
import { DIDDocumentEntity } from './did.entity';
import { LatestDidSync } from './latestDidSync.entity';
import { DIDProcessor } from './did.processor';
import { DIDResolver } from './did.resolver';
import { DIDService } from './did.service';
Expand All @@ -13,6 +14,7 @@ import { ConfigService } from '@nestjs/config';
import { BullModule } from '@nestjs/bull';
import { UPDATE_DOCUMENT_QUEUE_NAME } from './did.types';
import { PIN_CLAIM_QUEUE_NAME } from '../ipfs/ipfs.types';
import { DidSyncStatusEntity } from './didSyncStatus.entity';

const RegistrySettingsProvider = {
provide: 'RegistrySettings',
Expand All @@ -33,7 +35,11 @@ const RegistrySettingsProvider = {
BullModule.registerQueue({
name: PIN_CLAIM_QUEUE_NAME,
}),
TypeOrmModule.forFeature([DIDDocumentEntity]),
TypeOrmModule.forFeature([
DIDDocumentEntity,
LatestDidSync,
DidSyncStatusEntity,
]),
],
controllers: [DIDController],
providers: [
Expand Down
Loading
Loading