Don't cache prepared statements, they're pretty much unique at every
call.
Use VACUUM to re-organize library files during a wipe & rescan.

library.db is always VACUUMed after all the tables have been emptied. It
should be really quick on mostly empty databases.

persist.db only gets compressed when a certain level of fragmentation
(20%) is reached. Compressing it on every run might be too expensive, as
the data is mostly static anyway.