Skip to content

Commit

Permalink
fix: fix sentry module and add make more methods cacheable
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonn committed Aug 2, 2024
1 parent eaa040b commit b28213c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 620 deletions.
6 changes: 3 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.10",
"@nestjs/schedule": "^4.1.0",
"@ntegral/nestjs-sentry": "^4.0.1",
"@prisma/client": "^5.16.2",
"@rgbpp-sdk/btc": "^0.0.0-snap-20240727021715",
"@rgbpp-sdk/ckb": "^0.0.0-snap-20240727021715",
"@sentry/node": "^8.17.0",
"@sentry/profiling-node": "^8.17.0",
"@ntegral/nestjs-sentry": "^4.0.1",
"@sentry/node": "^7.116.0",
"@sentry/profiling-node": "^7.116.0",
"@types/ws": "^8.5.11",
"axios": "^1.7.2",
"bullmq": "^5.11.0",
Expand Down
4 changes: 2 additions & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import configModule from './config';
useFactory: async (configService: ConfigService<Env>) => ({
dsn: configService.get('SENTRY_DSN'),
environment: configService.get('NODE_ENV'),
tracesSampleRate: 0.1,
profilesSampleRate: 0.1,
tracesSampleRate: 0.5,
profilesSampleRate: 0.5,
integrations: [nodeProfilingIntegration()],
logLevels:
configService.get('NODE_ENV') === 'production'
Expand Down
10 changes: 5 additions & 5 deletions backend/src/core/ckb-explorer/ckb-explorer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ export class CkbExplorerService {
},
})
public async getTransaction(txHash: string): Promise<NonPaginatedResponse<DetailTransaction>> {
const key = `CkbExplorerService:getTransaction:${txHash}`;
const cached = await this.cacheManager.get(key);
if (cached) {
return cached as NonPaginatedResponse<DetailTransaction>;
}
const response = await this.request.get(`/v1/transactions/${txHash}`);
return response.data;
}

@Cacheable({
namespace: 'CkbExplorerService',
key: (txHash: string) => `getRgbppDigest:${txHash}`,
ttl: ONE_MONTH_MS,
})
public async getRgbppDigest(txHash: string): Promise<CkbExplorerResponse<RgbppDigest>> {
const response = await this.request.get(`/v2/ckb_transactions/${txHash}/rgb_digest`);
return response.data;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/middlewares/field-performance.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const fieldPerformanceMiddleware: FieldMiddleware = async (
const value = await next();

const executionTime = performance.now() - now;
if (executionTime > 100) {
if (executionTime > 300) {
const { path } = ctx.info;
logger.debug(`[${path.typename}.${path.key}]: ${executionTime}ms`);
}
Expand Down
5 changes: 4 additions & 1 deletion backend/src/modules/rgbpp/coin/coin.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export class RgbppCoin {
@Field(() => Float, { nullable: true })
transactionsCount: number;

public static from(xudt: CkbExplorer.XUDT): RgbppBaseCoin {
public static from(xudt: CkbExplorer.XUDT): RgbppBaseCoin | null {
if (!xudt) {
return null;
}
return {
name: xudt.full_name,
description: xudt.description,
Expand Down
10 changes: 6 additions & 4 deletions backend/src/modules/rgbpp/coin/coin.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

@Resolver(() => RgbppCoin)
export class RgbppCoinResolver {
constructor(private ckbExplorerService: CkbExplorerService) {}
constructor(private ckbExplorerService: CkbExplorerService) { }

@Query(() => RgbppCoinList, { name: 'rgbppCoins' })
public async coins(
Expand All @@ -26,18 +26,20 @@ export class RgbppCoinResolver {
sort,
tags: [XUDTTag.RgbppCompatible],
});
const coins = response.data.map((coin) => RgbppCoin.from(coin.attributes));
const coins = response.data
.map((coin) => RgbppCoin.from(coin.attributes))
.filter((coin) => coin !== null);
return {
coins,
total: response.meta.total,
pageSize: response.meta.page_size,
};
}

@Query(() => RgbppCoin, { name: 'rgbppCoin' })
@Query(() => RgbppCoin, { name: 'rgbppCoin', nullable: true })
public async coin(
@Args('typeHash', { type: () => String }) typeHash: string,
): Promise<RgbppBaseCoin> {
): Promise<RgbppBaseCoin | null> {
const response = await this.ckbExplorerService.getXUDT(typeHash);
return RgbppCoin.from(response.data.attributes);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type Query {
btcAddress(address: String!): BitcoinAddress
rgbppAddress(address: String!): RgbppAddress
rgbppCoins(page: Int, pageSize: Int, sort: TransactionListSortType): RgbppCoinList!
rgbppCoin(typeHash: String!): RgbppCoin!
rgbppCoin(typeHash: String!): RgbppCoin
rgbppStatistic: RgbppStatistic!
search(query: String!): SearchResult!
}
Expand Down
Loading

0 comments on commit b28213c

Please sign in to comment.