mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
RPC load reduction
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { Column, Entity, PrimaryColumn } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export class RpcBlockEntity {
|
||||
|
||||
@PrimaryColumn()
|
||||
blockHeight: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
lockedBy?: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
data?: string;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { RpcBlockEntity } from './rpc-block.entity';
|
||||
import { RpcBlockService } from './rpc-block.service';
|
||||
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([RpcBlockEntity])],
|
||||
providers: [RpcBlockService],
|
||||
exports: [TypeOrmModule, RpcBlockService],
|
||||
})
|
||||
export class RpcBlocksModule { }
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { RpcBlockEntity } from './rpc-block.entity';
|
||||
|
||||
@Injectable()
|
||||
export class RpcBlockService {
|
||||
constructor(
|
||||
@InjectRepository(RpcBlockEntity)
|
||||
private rpcBlockRepository: Repository<RpcBlockEntity>
|
||||
) {
|
||||
|
||||
}
|
||||
public getBlock(blockHeight: number) {
|
||||
return this.rpcBlockRepository.findOne({
|
||||
where: { blockHeight }
|
||||
});
|
||||
}
|
||||
|
||||
public lockBlock(blockHeight: number, process: string) {
|
||||
return this.rpcBlockRepository.save({ blockHeight, data: null, lockedBy: process });
|
||||
}
|
||||
|
||||
public saveBlock(blockHeight: number, data: string) {
|
||||
return this.rpcBlockRepository.update(blockHeight, { data })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user