Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -7,7 +7,7 @@ export class ApiKeyGuard implements CanActivate {

canActivate(context: ExecutionContext): boolean {
const req = context.switchToHttp().getRequest<Request>()
const key = req.headers['x-api-key']
const key = req.headers['x-api-key'] || req['query']?.['apiKey']
if (!key) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class PricesCrawlerProcessor {
}
}
`
const response = await this.graphqlClient.request(query, {
const response: any = await this.graphqlClient.request(query, {
tranche: job.tranche,
take: take,
timestamp: lastSynced,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { UtilService } from 'llp-aggregator-services/dist/util'
import { Injectable, Logger } from '@nestjs/common'
import { ElasticsearchService } from '@nestjs/elasticsearch'
import { WorkerService } from '../worker.service'
import {
BulkResponse,
DeleteByQueryResponse,
} from '@elastic/elasticsearch/lib/api/types'

@Injectable()
export class TimeFrameBuildProcessor {
Expand Down Expand Up @@ -90,69 +94,80 @@ export class TimeFrameBuildProcessor {
const id = this.utilService.generateAggregatedId(current)
removeItems[wallet].push(id)
operations.push({
create: {
update: {
_id: id,
},
})
operations.push(current)
operations.push({
doc: current,
doc_as_upsert: true,
})
})
}),
)
}),
)

const createResponse = await this.esService.bulk({
index: this.utilService.aggregatedDataIndex,
operations: operations,
refresh: true,
})
const deleteResponse = await this.esService.deleteByQuery({
index: this.utilService.aggregatedDataIndex,
query: {
bool: {
must: [
...Object.entries(removeItems).map(([wallet, ids]) => ({
bool: {
must: [
{
bool: {
must_not: {
terms: {
_id: ids,
let updateResponse: BulkResponse, deleteResponse: DeleteByQueryResponse
if (operations.length) {
updateResponse = await this.esService.bulk({
index: this.utilService.aggregatedDataIndex,
operations: operations,
refresh: true,
})
}
const removeEntities = Object.entries(removeItems)
if (removeEntities.length) {
deleteResponse = await this.esService.deleteByQuery({
index: this.utilService.aggregatedDataIndex,
query: {
bool: {
must: [
...Object.entries(removeItems).map(([wallet, ids]) => ({
bool: {
must: [
{
bool: {
must_not: {
terms: {
_id: ids,
},
},
},
},
},
{
term: {
wallet: wallet,
{
term: {
wallet: wallet,
},
},
},
],
},
})),
{
term: {
tranche: tranche,
],
},
})),
{
term: {
tranche: tranche,
},
},
},
],
],
},
},
},
conflicts: 'proceed',
refresh: true,
})
const [skipped, inserted] = [
createResponse.items.filter((c) => c?.create?.status === 409).length,
createResponse.items.filter((c) => c?.create?.status === 201).length,
conflicts: 'proceed',
refresh: true,
})
}
const [updated, inserted] = [
updateResponse?.items.filter((c) => c?.update?.status === 200).length ||
0,
updateResponse?.items.filter((c) => c?.update?.status === 201).length ||
0,
]
this.logger.debug(`
[update] info of lp performance
tranche: ${tranche}
skipped: ${skipped}
skipped: ${updated}
inserted: ${inserted}
deleted: ${deleteResponse.deleted}
failed: ${createResponse.items.length - skipped - inserted}
deleted: ${deleteResponse?.deleted}
failed: ${(updateResponse?.items.length || 0) - updated - inserted}
`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TimeFrameCronProcessor {
wallets.push(wallet)
}),
)
if (!wallets) {
if (!wallets || !wallets.length) {
return
}
await this.redisService.client.sadd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class UtilService {
}

generateAggregatedId(item: AggreatedData, chainId = this.chainId) {
const based = `${item.wallet}_${chainId}_${item.tranche}_${item.from}_${item.to}_${item.valueMovement.fee}_${item.valueMovement.pnl}_${item.valueMovement.price}`
const based = `${item.wallet}_${chainId}_${item.tranche}_${item.from}_${item.to}`
return utils.id(based)
}

Expand Down