Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use raw query to delete old token prices #38

Closed
wants to merge 12 commits into from
6 changes: 3 additions & 3 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async function startServer() {
enabled: env.NODE_ENV === 'production',
ignoreErrors: [/.*error: Provide.*chain.*param/],
integrations: [
new Sentry.Integrations.Apollo(),
new Sentry.Integrations.GraphQL(),
new Sentry.Integrations.Prisma({ client: prisma }),
// new Sentry.Integrations.Apollo(),
// new Sentry.Integrations.GraphQL(),
// new Sentry.Integrations.Prisma({ client: prisma }),
new Sentry.Integrations.Express({ app }),
new Sentry.Integrations.Http({ tracing: true }),
new ProfilingIntegration(),
Expand Down
24 changes: 3 additions & 21 deletions modules/token/lib/token-price.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,28 +256,10 @@ export class TokenPriceService {
}

public async purgeOldTokenPricesForAllChains(): Promise<number> {
const purgeBeforeTimestamp = moment().startOf('day').subtract(100, 'days').utc().unix();
const oldPrices = await prisma.prismaTokenPrice.findMany({
where: {
timestamp: { lt: purgeBeforeTimestamp },
},
});

// returns all non midnight prices
const tobeDeleted = _.uniq(oldPrices.filter((tokenPrice) => tokenPrice.timestamp % secondsPerDay !== 0));

//apparently prisma has a limitation on delete
const chunks = _.chunk(tobeDeleted, 1000);

for (const chunk of chunks) {
await prisma.prismaTokenPrice.deleteMany({
where: {
timestamp: { in: chunk.map((tokenPrice) => tokenPrice.timestamp) },
},
});
}
const deleted =
await prisma.$executeRaw`DELETE FROM "PrismaTokenPrice" WHERE DATE(to_timestamp(timestamp)) != to_timestamp(timestamp) AND to_timestamp(timestamp) < CURRENT_DATE - INTERVAL '100 days'`;

return tobeDeleted.length;
return deleted;
}

private async updateCandleStickData() {
Expand Down
8 changes: 4 additions & 4 deletions worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export async function startWorker() {
environment: `multichain-worker-${env.DEPLOYMENT_ENV}`,
enabled: env.NODE_ENV === 'production',
integrations: [
new Sentry.Integrations.Apollo(),
new Sentry.Integrations.GraphQL(),
new Sentry.Integrations.Prisma({ client: prisma }),
new Sentry.Integrations.Express({ app }),
// new Sentry.Integrations.Apollo(),
// new Sentry.Integrations.GraphQL(),
// new Sentry.Integrations.Prisma({ client: prisma }),
// new Sentry.Integrations.Express({ app }),
new Sentry.Integrations.Http({ tracing: true }),
new ProfilingIntegration(),
],
Expand Down