CounterpartyXCP/counterpartyd — pull request #329 by JahPowerBit (2014-10-10 13:50:42+00:00)
Title: [#295] no sql query in generate_movement_hash

1) To avoid querying the current_hash, I used the block['movements_hash'] from reparse function: https://github.com/JahPowerBit/counterpartyd/blob/develop/lib/blocks.py#L1157

2) To avoid making `select`queries on `credits` and `debits`, I use a global variable `util.BLOCK_MOVEMENTS`. This variable is populated in `util.credit`and `util.debit`functions:
https://github.com/JahPowerBit/counterpartyd/blob/develop/lib/util.py#L531
https://github.com/JahPowerBit/counterpartyd/blob/develop/lib/util.py#L582
And emptied each block after the movements_hash is calculated:
https://github.com/JahPowerBit/counterpartyd/blob/develop/lib/blocks.py#L141

Notes:
- with this method, on my dev environment, reparsing takes 390s instead 1100s
- Generally I really don't like global variable, but in this case I have not found another method to avoid `select` queries on `credits` and `debits` (these queries take most of the time in the actual method).
- movement hashes are changed (because I don't use anymore the rowid to calculate the hash). Before testing use `UPDATE blocks SET movements_hash=NULL;` and reparse twice (first to populate `blocks` table and second to compare hashes)