Delete feeds and folders by ids and by account id (closes #100)

This commit is contained in:
Shinokuni 2021-07-16 17:51:23 +02:00
parent d51c7ed90a
commit ef195b4231
2 changed files with 11 additions and 12 deletions

View File

@ -29,9 +29,6 @@ public abstract class FeedDao implements BaseDao<Feed> {
@Query("Select * from Feed Where id = :feedId")
public abstract Feed getFeedById(int feedId);
@Query("Select id From Feed Where url = :url and account_id = :accountId")
public abstract int getFeedIdByUrl(String url, int accountId);
@Query("Select case When :feedUrl In (Select url from Feed Where account_id = :accountId) Then 1 else 0 end")
public abstract boolean feedExists(String feedUrl, int accountId);
@ -81,8 +78,8 @@ public abstract class FeedDao implements BaseDao<Feed> {
@Query("Select remoteId From Feed Where account_id = :accountId")
public abstract List<String> getFeedRemoteIdsOfAccount(int accountId);
@Query("Delete from Feed Where remoteId in (:ids)")
abstract void deleteByIds(List<String> ids);
@Query("Delete from Feed Where remoteId in (:ids) And account_id = :accountId")
abstract void deleteByIds(List<String> ids, int accountId);
@Query("Select id From Folder Where remoteId = :remoteId And account_id = :accountId")
abstract int getRemoteFolderLocalId(String remoteId, int accountId);
@ -126,8 +123,9 @@ public abstract class FeedDao implements BaseDao<Feed> {
}
}
if (!accountFeedIds.isEmpty())
deleteByIds(accountFeedIds);
if (!accountFeedIds.isEmpty()) {
deleteByIds(accountFeedIds, account.getId());
}
return insert(feedsToInsert);
}

View File

@ -36,8 +36,8 @@ public abstract class FolderDao implements BaseDao<Folder> {
@Query("Select remoteId From Folder Where account_id = :accountId")
public abstract List<String> getFolderRemoteIdsOfAccount(int accountId);
@Query("Delete From Folder Where remoteId in (:ids)")
abstract void deleteByIds(List<String> ids);
@Query("Delete From Folder Where remoteId in (:ids) And account_id = :accountId")
abstract void deleteByIds(List<String> ids, int accountId);
@Query("Select * From Folder Where name = :name And account_id = :accountId")
public abstract Folder getFolderByName(String name, int accountId);
@ -47,7 +47,7 @@ public abstract class FolderDao implements BaseDao<Folder> {
*
* @param folders folders to insert or update
* @param account owner of the feeds
* @return the list of the inserted feeds ids
* @return the list of the inserted folders ids
*/
@Transaction
public List<Long> foldersUpsert(List<Folder> folders, Account account) {
@ -64,8 +64,9 @@ public abstract class FolderDao implements BaseDao<Folder> {
}
}
if (!accountFolderIds.isEmpty())
deleteByIds(accountFolderIds);
if (!accountFolderIds.isEmpty()) {
deleteByIds(accountFolderIds, account.getId());
}
return insert(foldersToInsert);
}