Skip to content

Commit

Permalink
Remove id from feed group when feed is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Apr 16, 2024
1 parent dcdf041 commit 5a90a1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,17 @@ class RssRepository(
}

suspend fun removeFeed(feedId: String) {
withContext(ioDispatcher) { feedQueries.remove(feedId) }
withContext(ioDispatcher) {
feedQueries.remove(feedId)
val feedGroup = feedGroupQueries.groupByFeedId(feedId).executeAsOneOrNull()

if (feedGroup != null) {
feedGroupQueries.updateFeedIds(
feedIds = feedGroup.feedIds - setOf(feedId),
id = feedGroup.id
)
}
}
}

suspend fun updateFeedName(newFeedName: String, feedId: String) {
Expand Down Expand Up @@ -612,6 +622,17 @@ class RssRepository(
sources.forEach { source ->
feedQueries.remove(id = source.id)
feedGroupQueries.deleteGroup(id = source.id)

if (source is Feed) {
val feedGroup = feedGroupQueries.groupByFeedId(feedId = source.id).executeAsOneOrNull()

if (feedGroup != null) {
feedGroupQueries.updateFeedIds(
feedIds = feedGroup.feedIds - setOf(source.id),
id = feedGroup.id
)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ DELETE FROM feedGroup WHERE id = :id;

updatePinnedAt:
UPDATE feedGroup SET pinnedAt = :pinnedAt WHERE id = :id;

groupByFeedId:
SELECT * FROM feedGroup WHERE INSTR(feedIds, :feedId);

0 comments on commit 5a90a1e

Please sign in to comment.