Update stat data on flush and not for each write

This should greatly reduce the number of IndexedDB transactions we create.
Will do, in my initial implementation the idea was to only set the data in flush (even if it wouldn't have been completely correct).