Skip to content

Commit

Permalink
Merge pull request #180 from helix-bridge/xiaoch05-optimise-lnv3
Browse files Browse the repository at this point in the history
optimise lnv3
  • Loading branch information
xiaoch05 authored Oct 16, 2024
2 parents 2b2e22a + f24a9bf commit fb58efb
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 270 deletions.
7 changes: 7 additions & 0 deletions apollo/prisma/migrations/20241014083428_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "ScanCursor" (
"id" TEXT NOT NULL,
"cursor" BIGINT NOT NULL,

CONSTRAINT "ScanCursor_pkey" PRIMARY KEY ("id")
);
5 changes: 5 additions & 0 deletions apollo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ model HistoryRecord {
extData String?
}

model ScanCursor {
id String @id
cursor BigInt
}

model LnBridgeRelayInfo {
id String @id
version String
Expand Down
32 changes: 32 additions & 0 deletions apollo/src/aggregation/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
});
}

async writeCursor(id: string, cursor: bigint) {
return await this.scanCursor.upsert({
where: { id: id },
update: { cursor: cursor },
create: { id: id, cursor: cursor },
});
}

async readCursor(id: string): Promise<bigint> {
const cursor = await this.scanCursor.findUnique({
where: { id: id },
});
if (cursor) {
return cursor.cursor;
} else {
return BigInt(0);
}
}

async createHistoryRecord(data: Prisma.HistoryRecordCreateInput): Promise<HistoryRecord> {
return this.historyRecord.create({
data,
Expand All @@ -51,6 +70,19 @@ export class AggregationService extends PrismaClient implements OnModuleInit {
});
}

async saveHistoryRecord(params: {
where: Prisma.HistoryRecordWhereUniqueInput;
dataCreate: Prisma.HistoryRecordCreateInput;
dataUpdate: Prisma.HistoryRecordUpdateInput;
}): Promise<HistoryRecord> {
const { where, dataCreate, dataUpdate } = params;
return await this.historyRecord.upsert({
where: where,
update: dataUpdate,
create: dataCreate,
});
}

async queryLnBridgeRelayInfoFirst(
lnBridgeRelayInfoWhereInput: Prisma.LnBridgeRelayInfoWhereInput,
orderBy?: Prisma.Enumerable<Prisma.LnBridgeRelayInfoOrderByWithRelationAndSearchRelevanceInput>
Expand Down
Loading

0 comments on commit fb58efb

Please sign in to comment.