Skip to content

🚀 feat: Add save time tracking to prevent frequent contract saves#1913

Merged
mkmccarty merged 3 commits intomainfrom
mm-branch-1
Dec 8, 2025
Merged

🚀 feat: Add save time tracking to prevent frequent contract saves#1913
mkmccarty merged 3 commits intomainfrom
mm-branch-1

Conversation

@mkmccarty
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings December 8, 2025 21:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a throttling mechanism to prevent frequent contract saves by tracking the last save time and enforcing a minimum 15-second interval between saves.

  • Added LastSaveTime field to the Contract struct to track when contracts were last persisted
  • Implemented save throttling logic in saveData() that checks if 15 seconds have passed since the last save
  • Added nil check for contract before attempting to access its fields

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/boost/boost.go Added LastSaveTime field to Contract struct to track save timestamps
src/boost/boost_datastore.go Implemented save throttling logic with 15-second minimum interval and added nil contract check

Comment on lines 76 to 77
if contract.LastSaveTime.Before(time.Now().Add(-15 * time.Second)) {
contract.LastSaveTime = time.Now()
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The LastSaveTime field is not protected by the contract's mutex, which could lead to race conditions in concurrent access scenarios. Since the Contract struct has a mutex sync.Mutex field (line 325), and LastSaveTime is being read and written in saveData(), these operations should be protected with mutex locks.

Consider wrapping the time check and update in a mutex lock:

contract.mutex.Lock()
shouldSave := time.Since(contract.LastSaveTime) >= 15*time.Second
if shouldSave {
    contract.LastSaveTime = time.Now()
}
contract.mutex.Unlock()

if shouldSave {
    saveSqliteData(contract)
}
Suggested change
if contract.LastSaveTime.Before(time.Now().Add(-15 * time.Second)) {
contract.LastSaveTime = time.Now()
contract.mutex.Lock()
shouldSave := contract.LastSaveTime.Before(time.Now().Add(-15 * time.Second))
if shouldSave {
contract.LastSaveTime = time.Now()
}
contract.mutex.Unlock()
if shouldSave {

Copilot uses AI. Check for mistakes.
mkmccarty and others added 2 commits December 8, 2025 13:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mkmccarty mkmccarty merged commit d158a1b into main Dec 8, 2025
12 checks passed
@mkmccarty mkmccarty deleted the mm-branch-1 branch December 8, 2025 21:42
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.

1 participant