Skip to content

Feat: delete pg history#566

Merged
anihamde merged 13 commits intomainfrom
feat/delete-pg-history
Jun 4, 2025
Merged

Feat: delete pg history#566
anihamde merged 13 commits intomainfrom
feat/delete-pg-history

Conversation

@anihamde
Copy link
Contributor

@anihamde anihamde commented Jun 3, 2025

This PR adds a loop to delete old rows in the Postgres bid and opportunity tables. The arguments are optional, and, if not provided, will not induce any deletion.

@vercel
Copy link

vercel bot commented Jun 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
swap-staging ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2025 9:30am

_ = delete_history_interval.tick() => {
let threshold = OffsetDateTime::now_utc() - Duration::from_secs(delete_threshold_secs);

sqlx::query!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query may take a long time, I suggest to delete limited number of rows each time. Sth like 1000

@danimhr
Copy link
Contributor

danimhr commented Jun 3, 2025

@anihamde You need to generate the sqlx queries for github ci

let threshold_opportunity = OffsetDateTime::now_utc() - Duration::from_secs(delete_threshold_secs);
while n_opportunities_deleted.unwrap_or(DELETE_BATCH_SIZE) >= DELETE_BATCH_SIZE {
n_opportunities_deleted = Some(sqlx::query!(
"WITH rows_to_delete AS (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add chain_id for the opp as well. As far as I remember, we had no index on creation_time here :-?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a while, you can run a single delete query per tick and reduce the deletion tick interval. I dont feel good about this while loop inside the tokio selecct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good point. i can tie this to run across all chains, but keeping the same params

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Can you get rid of the while loop and set the limit to 5K and run it every 1 seconds?
You can also create a function for deletion and add instrument around it to make sure the delete query is fast enough

/// How often to delete rows from the database.
#[arg(long = "delete-interval-seconds")]
#[arg(env = "DELETE_INTERVAL_SECONDS")]
#[arg(default_value = "60")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run it every second?

Copy link
Contributor

@danimhr danimhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, please make sure you are running the deletion loop every second.
I think you just need to update the default value for deletion loop.

  • I think 1000 is very small for deletion. We may have more bid than that per second. I suggest to increase it to 5000 and

@anihamde anihamde merged commit 0088d4a into main Jun 4, 2025
3 checks passed
@anihamde anihamde deleted the feat/delete-pg-history branch June 4, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants