Skip to content

Commit

Permalink
fix: only save when there are changes to be saved
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Oct 4, 2024
1 parent 9e661e1 commit 0cd76e5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/domain/polling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const API_ERRORS_DROP: DropApiErrorsArray = [
// ApiErrors.IncompatibleSigningScheme - we control this in the watch-tower
// ApiErrors.AppDataHashMismatch - we never submit full appData

const CHUNK_SIZE = 100; // How many orders to process before saving
const CHUNK_SIZE = 50; // How many orders to process before saving

/**
* Watch for new blocks and check for orders to place
Expand All @@ -115,6 +115,7 @@ export async function checkForAndPlaceOrder(
let hasErrors = false;
let ownerCounter = 0;
let orderCounter = 0;
let updatedCount = 0;

const log = getLogger(
"checkForAndPlaceOrder:checkForAndPlaceOrder",
Expand All @@ -140,13 +141,13 @@ export async function checkForAndPlaceOrder(
orderCounter++;

// Check if we reached the chunk size
if (orderCounter % CHUNK_SIZE === 1 && orderCounter > 1) {
if (updatedCount % CHUNK_SIZE === 1 && updatedCount > 1) {
// Delete orders pending delete, if any
_deleteOrders(ordersPendingDelete, conditionalOrders, log, chainId);
// Reset tracker
ordersPendingDelete = [];

log.debug(`Processed ${orderCounter}, saving registry`);
log.debug(`Processed ${updatedCount}, saving registry`);

// Save the registry after processing each chunk
// await registry.write(); // TODO: temporarily disabling save on chunk
Expand Down Expand Up @@ -231,6 +232,8 @@ export async function checkForAndPlaceOrder(
blockNumber: blockNumber,
result: pollResult,
};
// Order needs saving!
updatedCount++;

// Log the result
const unexpectedError =
Expand Down

0 comments on commit 0cd76e5

Please sign in to comment.