Skip to content

Improve updateTradesHistory performance#84

Open
primersion wants to merge 3 commits intohive-engine:qafrom
primersion:qa_add_index_to_trades_history
Open

Improve updateTradesHistory performance#84
primersion wants to merge 3 commits intohive-engine:qafrom
primersion:qa_add_index_to_trades_history

Conversation

@primersion
Copy link
Contributor

@primersion primersion commented Jan 5, 2025

This PR tries to improve the updateTradesHistory method of the market contract:

  • adds an index for the timestamp column of the market_tradesHistory table
  • call updateVolumeMetric only once

@primersion primersion changed the title Add index for market_tradesHistory table timestamp column Improve updateTradesHistory performance Jan 5, 2025
Copy link
Contributor

@bt-cryptomancer bt-cryptomancer left a comment

Choose a reason for hiding this comment

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

Mostly looks good (see one comment below). However, I'd like to see a before & after test case added to do a bit of profiling to see how much of a difference this makes. You could have a test case that does, say, 10,000 trades, then update the block time and measure how long in ms it takes to clean up the tradesHistory table. Then deploy the updated contract and measure again to see if there is a noticeable difference with this change.

Also, can you look into why this didn't pass all the automated github tests?

await removeBadOrders();
await removeBlacklistedOrders('buy', 'waitingforlove');
await removeBlacklistedOrders('sell', 'waitingforlove');
await api.db.addIndexes('tradesHistory', [{ name: 'timestamp', index: { timestamp: 1 } }]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you gate this new index addition behind a params.updateIndex check in the same way as the mining contract?

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