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

feat: cleanup old entries in the sqlite #21

Open
ppedziwiatr opened this issue Jan 20, 2023 · 3 comments
Open

feat: cleanup old entries in the sqlite #21

ppedziwiatr opened this issue Jan 20, 2023 · 3 comments
Assignees

Comments

@ppedziwiatr
Copy link
Contributor

ppedziwiatr commented Jan 20, 2023

run periodically (once a day?):

DELETE
FROM states
WHERE sort_key IN (SELECT sort_key
                   FROM (SELECT *,
                                ROW_NUMBER() OVER (PARTITION BY contract_tx_id ORDER BY sort_key DESC) AS n
                         FROM states) AS x
                   WHERE n > 3);
                   
VACUUM;                   

on the node.sqlite db.

Watch out for the WAL file size after cleanup - rm might be needed.

@ppedziwiatr
Copy link
Contributor Author

or maybe remove the entries on the fly, while new are being inserted (though this will slow down the insertion process...)

@ppedziwiatr
Copy link
Contributor Author

..or maybe simply keep only one state per contract....which may result in a slight risk of that newer state will be overwritten by the older one (if the evaluation of the the 'older' interaction will happen to end after evaluation for the 'newer' interaction - in a scenario, where contract has a lot of interactions registered in a short period of time)

@janekolszak
Copy link
Contributor

UNIQUE on contractID, trigger function that neglects INSERT if sortKey is smaller that the inserted

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

No branches or pull requests

2 participants