ribbons / RadioDownloader

An easy to use application for managing podcast subscriptions and downloads.
https://nerdoftheherd.com/tools/radiodld/
GNU General Public License v3.0
15 stars 11 forks source link

Added automatic pruning of never-downloaded programme data from database #210

Closed ribbons closed 4 years ago

ribbons commented 8 years ago

Although the situation was greatly improved by #61, the application database (store.db) still grows in size over time.

Analysing the contents of my own database, a lot of the data (images especially) appear to be for programmes which have had the list of available episodes viewed at some point but have never had any episodes downloaded. This isn't covered by the database Prune routine added as part of #61 as that only cleans up images for episodes marked as unavailable (which requires the available episodes list to be fetched regularly by repeated viewing or a subscription).

To remedy this issue I propose adding the following additional cleanup commands to the DatabaseInit.Prune function:

delete from episodes where progid in
    (select progid from programmes p where lastupdate < date('now', '-1 year') and
        (select count(*) from episodes e where e.progid=p.progid and autodownload=0) = 0 and
        (select count(*) from episodes e inner join downloads d on e.progid=p.progid and e.epid=d.epid) = 0 and
        (select count(*) from subscriptions s where s.progid=p.progid) = 0 and
        (select count(*) from favourites f where f.progid=p.progid) = 0 and
        (select count(*) from episodes e where e.progid=p.progid and e.date > date('now', '-1 year')) = 0
    );

This first command deletes all episode information for programmes which:

Some of these are probably a bit redundant but I think it pays to err on the side of caution with this sort of cleanup.

delete from programmes where progid in
    (select progid from programmes p where lastupdate < date('now', '-1 year') and
        (select count(*) from episodes e where e.progid=p.progid) = 0 and
        (select count(*) from subscriptions s where s.progid=p.progid) = 0 and
        (select count(*) from favourites f where f.progid=p.progid) = 0
    );

This second command removes the programme entries themselves which have had their episodes deleted by the above.

ribbons commented 8 years ago

After a prune and vacuum, my database was just over 300MB.

Running the above commands manually and then another prune and vacuum took it to 174MB.

ribbons commented 4 years ago

Implemented roughly as originally described but made use of the foreign key constraints added since then to enable all of the cleanup to be performed from a single SQL statement.