Cleanup of old unlisted episodes

App version: 3.6.0 from android play store

Problem you may be having, or feature you want:
Database takes 80MB.
I have 52000 episodes in the table “FeedItems”.

In particular, I have this feed Portada iVoox that publishes dozens of episodes daily. In the feed there only like 10 active episodes, but AntennaPod has kept track of 30000, and never deletes them.

It is nice that AntennaPod remembers episodes that disappear from the feed, but there may be a limit.

I’m trying to manually export/edit/import the database, but I’m afraid of screwing it up.

Suggested solution:
Possible solutions:

  • An option to auto-delete old episodes that are not in the RSS, not downloaded, not in queue, not favourites, etc.
  • A button to perform this operation at will.

Screenshots / Drawings / Technical details:

This request on our development platform: Remove episodes no longer in the RSS feed from episode lists · Issue #4426 · AntennaPod/AntennaPod · GitHub (have a look there for some counter-arguments)

This is my attempt to do a manual cleanup. Startup time changed from a couple seconds to virtually instant.

What it does is delete items except:

  • Published in the last 30 days
  • Played listened in the last 30 days
  • Favorites
  • Queue
  • Downloaded

It also deletes all the corresponding orphaned media and chapters.

If you want to modify the “30” beware that there 2 places wheter it appeans in the query (not counting comments).
Instructions:

  1. Export database using menu
  2. Copy to PC
  3. Open with sqlite3
  4. Run commands and exit
  5. Copy back to phone
  6. Import

Use it at your own risk!!

/* Delete items older than 30 days */
delete from feeditems where id in (
    select 
        feeditems.id
    from feeditems
        left join queue on queue.feeditem=feeditems.id
        left join favorites on favorites.feeditem=feeditems.id
        left join feedmedia on feedmedia.feeditem=feeditems.id
    where 
    pubDate/1000  <  unixepoch() - 86400 * 30
    and ( last_played_time is null
       OR last_played_time/1000  <  unixepoch() - 86400 * 30
    )
    and queue.id is null
    and favorites.id is null
    and ( downloaded is null or downloaded=0 )
);

/* Delete orphan chapters */
delete from simplechapters where feeditem not in (select id from feeditems);

/* Delete orphan media */
delete from feedmedia where feeditem not in (select id from feeditems);