Last active
October 12, 2016 12:36
-
-
Save jmiettinen/23a38c10d18c9f5b048480e7da0fa15c to your computer and use it in GitHub Desktop.
Given start timestamp and end timestamp, we go through all snapshots between those two until a given block returns true. The block is given a Trx which can then be queried
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BE CAREFUL WITH THE END TIMESTAMP SO THAT YOU DON'T GO TOO FAR INTO THE PAST | |
# IN CASE THERE'S NO MATCHING SNAPSHOT | |
def find_snapshot(start_timestamp, end_timestamp = start_timestamp - 1, &block); | |
end_timestamp = end_timestamp > 0 ? end_timestamp : 0; | |
earlier = nil; | |
current_timestamp = start_timestamp; | |
while current_timestamp > end_timestamp do; | |
current_ss = FastormDb.database.get_snapshot(current_timestamp); | |
if block.call(current_ss.begin_trx); | |
return {:current => current_timestamp, :earlier => earlier }; | |
end; | |
current_timestamp, earlier = current_ss.parent_timestamp, current_timestamp; | |
end; | |
return {:current => current_timestamp, :earlier => earlier }; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment