-
Notifications
You must be signed in to change notification settings - Fork 68
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
Trim Old Blocks #100
Trim Old Blocks #100
Conversation
@@ -74,6 +76,33 @@ function updateBlocks(user) { | |||
logger.error(err); | |||
}).success(function(blockBatch) { | |||
fetchAndStoreBlocks(blockBatch, user.access_token, user.access_token_secret); | |||
destroyOldBlocks(user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destroyOldBlocks should only get called when we are finished with a batch and set the 'complete' flag. Otherwise we can wind up with the most recently collected batches being incomplete ones.
BTW, this has to wait on submission until #102 is in, or the delete cascades won't actually work. Note: If you're running locally you may already have these foreign key constraints from sequelize.sync(). The prod instance doesn't because the associations between models were added after initial DB creation. |
Moved |
a31a863
to
43350bf
Compare
Call destroyOldBlocks in finalizeBlockBatch to remove all but two latest BlockBatches for user when a new BlockBatch is retrieved successfully.
43350bf
to
ad8330b
Compare
Rebased on master (foreign key constraints, store size on BlockBatch, &c) |
@@ -168,11 +169,45 @@ function finalizeBlockBatch(blockBatch) { | |||
blockBatch.save().error(function(err) { | |||
logger.error(err); | |||
}).success(function(blockBatch) { | |||
// Prune older BlockBatches for this user from the DB. | |||
BtUser.find({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify this by leaving out the BtUser.find. Just pass the source_uid to destroyOldBlocks, and it can do a
BlockBatch.findAll({
where: { source_uid: source_uid }
}
For some reason I thought we might want access to the BtUser record in |
One more small thing: Could you check if the offset and order options work for Also, can you double check the SQL output? By my understanding, the destroy command you have is missing a |
Destroy's first argument is a WHERE object, see here You can't provide offset in LIMIT clause of mySQL DELETE query; best you can do is hack around it using subquery a la:
which isn't performant or legible! |
Excellent, thanks for looking into it! Merging. |
Addresses #59
When a new BlockBatch is fetched in
updateBlocks
, trim BlockBatches in DB to only include 2 most recent for this BtUser.Deleting BlockBatch items will clean up Blocks table automatically via cascade.