From ef195b4231ff2ff1f391ff4baacd27315ca519c8 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 16 Jul 2021 17:51:23 +0200 Subject: [PATCH] Delete feeds and folders by ids and by account id (closes #100) --- db/src/main/java/com/readrops/db/dao/FeedDao.java | 12 +++++------- db/src/main/java/com/readrops/db/dao/FolderDao.java | 11 ++++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/db/src/main/java/com/readrops/db/dao/FeedDao.java b/db/src/main/java/com/readrops/db/dao/FeedDao.java index f1a70691..af171860 100644 --- a/db/src/main/java/com/readrops/db/dao/FeedDao.java +++ b/db/src/main/java/com/readrops/db/dao/FeedDao.java @@ -29,9 +29,6 @@ public abstract class FeedDao implements BaseDao { @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 { @Query("Select remoteId From Feed Where account_id = :accountId") public abstract List getFeedRemoteIdsOfAccount(int accountId); - @Query("Delete from Feed Where remoteId in (:ids)") - abstract void deleteByIds(List ids); + @Query("Delete from Feed Where remoteId in (:ids) And account_id = :accountId") + abstract void deleteByIds(List 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 { } } - if (!accountFeedIds.isEmpty()) - deleteByIds(accountFeedIds); + if (!accountFeedIds.isEmpty()) { + deleteByIds(accountFeedIds, account.getId()); + } return insert(feedsToInsert); } diff --git a/db/src/main/java/com/readrops/db/dao/FolderDao.java b/db/src/main/java/com/readrops/db/dao/FolderDao.java index b527c4df..75f1b507 100644 --- a/db/src/main/java/com/readrops/db/dao/FolderDao.java +++ b/db/src/main/java/com/readrops/db/dao/FolderDao.java @@ -36,8 +36,8 @@ public abstract class FolderDao implements BaseDao { @Query("Select remoteId From Folder Where account_id = :accountId") public abstract List getFolderRemoteIdsOfAccount(int accountId); - @Query("Delete From Folder Where remoteId in (:ids)") - abstract void deleteByIds(List ids); + @Query("Delete From Folder Where remoteId in (:ids) And account_id = :accountId") + abstract void deleteByIds(List 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 { * * @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 foldersUpsert(List folders, Account account) { @@ -64,8 +64,9 @@ public abstract class FolderDao implements BaseDao { } } - if (!accountFolderIds.isEmpty()) - deleteByIds(accountFolderIds); + if (!accountFolderIds.isEmpty()) { + deleteByIds(accountFolderIds, account.getId()); + } return insert(foldersToInsert); }