Skip to content

Commit

Permalink
Don't clean up podcast if it's downloaded
Browse files Browse the repository at this point in the history
This patch makes podcasts that are downloaded not get removed when
cleaning up database when oversized.

Signed-off-by: Marcus Nilsson <[email protected]>
  • Loading branch information
mkanilsson committed Jan 13, 2024
1 parent 7a5a66d commit f8a9d56
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public enum SORT_DIRECTION { asc, desc }

private final static int PageSize = 25;

private Context context;

protected @Inject @Named("databaseFileName") String databasePath;

public void resetDatabase() {
Expand All @@ -80,6 +82,7 @@ public void resetDatabase() {
}

public DatabaseConnectionOrm(Context context) {
this.context = context;
if(databasePath == null) {
((NewsReaderApplication) context.getApplicationContext()).getAppComponent().injectDatabaseConnection(this);
}
Expand Down Expand Up @@ -782,9 +785,13 @@ public void clearDatabaseOverSize()
if(overSize > read)
overSize = read;

var downloadedPodcastsFingerprints = NewsFileUtils.getDownloadedPodcastsFingerprints(context);
var files = Arrays.stream(downloadedPodcastsFingerprints).map((f) -> "\"" + f + "\"").collect(Collectors.toList());

String sqlStatement = "DELETE FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Id.columnName +
" IN (SELECT " + RssItemDao.Properties.Id.columnName + " FROM " + RssItemDao.TABLENAME +
" WHERE " + RssItemDao.Properties.Read_temp.columnName + " = 1 AND " + RssItemDao.Properties.Starred_temp.columnName + " != 1 " +
" AND " + RssItemDao.Properties.Fingerprint.columnName + " NOT IN (" + String.join(",", files) + ")" + // This means that the article has downloaded podcast media
" AND " + RssItemDao.Properties.Id.columnName + " NOT IN (SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")" +
" ORDER BY " + RssItemDao.Properties.Id.columnName + " asc LIMIT " + overSize + ")";
daoSession.getDatabase().execSQL(sqlStatement);
Expand Down

0 comments on commit f8a9d56

Please sign in to comment.