Update stat data on flush and not for each write

This should greatly reduce the number of IndexedDB transactions we create.