Skip to content

Commit

Permalink
Merge pull request #11 from push-protocol/dev0
Browse files Browse the repository at this point in the history
benchmark fixes
  • Loading branch information
Igx22 authored Dec 6, 2024
2 parents d701d80 + fb97a26 commit 056db37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AppModule } from './app.module';
import { WinstonLoggerService } from './common/logger/winston-logger.service';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { StrUtil } from './utilz/strUtil';
import { json } from 'body-parser';

function fixDatabaseUrl() {
if (StrUtil.isEmpty(process.env.DATABASE_URL)) {
Expand All @@ -24,6 +25,8 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: new WinstonLoggerService(),
});
const MAX_HTTP_PAYLOAD = EnvLoader.getPropertyOrDefault('MAX_HTTP_PAYLOAD', '20mb');
app.use(json({ limit: MAX_HTTP_PAYLOAD }));

app.enableCors({
origin: '*', // Specify the client origin or use '*' for wide open access
Expand Down
12 changes: 7 additions & 5 deletions src/modules/block/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { StrUtil } from '../../utilz/strUtil';
import { DateUtil } from '../../utilz/dateUtil';
import { Check } from '../../utilz/check';
import { NumUtil } from '../../utilz/numUtil';
import { CaipAddr, ChainUtil } from '../../utilz/chainUtil';

@Injectable()
export class BlockService {
Expand Down Expand Up @@ -224,27 +225,28 @@ export class BlockService {
if (StrUtil.isEmpty(sort)) {
sort = 'DESC';
}
Check.isTrue(ChainUtil.isFullCAIPAddress(walletInCaip), 'invalid wallet, only caip10 format is supported' + walletInCaip);
Check.isTrue(sort === 'ASC' || sort === 'DESC', 'invalid sort');
Check.isTrue(pageSize > 0 && pageSize <= 1000, 'invalid pageSize');
const isFirstQuery = StrUtil.isEmpty(firstTs);
let firstTsSeconds = DateUtil.parseUnixFloatOrFail(firstTs);
let firstTsMillis = DateUtil.unixFloatToMillis(firstTsSeconds);
Check.isTrue(isFirstQuery || firstTsSeconds != null);
const comparator = sort === 'ASC' ? '>' : '<';
const recipientJson = JSON.stringify({ recipients: [{ address: walletInCaip }] });

let sql = `select ts, txn_hash, data_as_json
from "Transaction"
where category=$1 and sender=$2
${isFirstQuery ? '' : `and ts ${comparator} $3`}
where category=$1 and (sender=$2 OR recipients @> $3::jsonb)
${isFirstQuery ? '' : `and ts ${comparator} $4`}
order by ts ${sort}
FETCH FIRST ${pageSize} ROWS WITH TIES`;
this.log.debug('query: %s', sql);
const rows = await this.prisma.$queryRawUnsafe<
Array<{ ts: BigInt; txn_hash: string, data_as_json: any }>
>(
sql,
category,
walletInCaip,
firstTsMillis
category, walletInCaip, recipientJson, firstTsMillis
);
const itemsArr = rows.map((row) => {
let tx:{ fee: string, data: string, type: number, sender: string, category: string, recipientsList: string} = row.data_as_json.tx;
Expand Down

0 comments on commit 056db37

Please sign in to comment.