Skip to content

Commit 165bcf3

Browse files
[Bug] fixed tags deletion (#128)
* fixed tags deletion not working when links are deleted and that tag has only one link * fix --------- Co-authored-by: anas shikoh <[email protected]>
1 parent 34cc3ce commit 165bcf3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

app/src/main/java/com/yogeshpaliyal/deepr/viewmodel/AccountViewModel.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,20 @@ class AccountViewModel(
230230

231231
fun deleteAccount(id: Long) {
232232
viewModelScope.launch(Dispatchers.IO) {
233+
val tagsToDelete = mutableListOf<Long>()
234+
235+
deeprQueries.getTagsForLink(id).executeAsList().forEach { tag ->
236+
val linkCount = deeprQueries.hasTagLinks(tag.id).executeAsOne()
237+
if (linkCount == 1L) {
238+
tagsToDelete.add(tag.id)
239+
}
240+
}
241+
233242
deeprQueries.deleteDeeprById(id)
234243
deeprQueries.deleteLinkRelations(id)
244+
tagsToDelete.forEach { tagId ->
245+
deeprQueries.deleteTag(tagId)
246+
}
235247
}
236248
}
237249

app/src/main/sqldelight/com/yogeshpaliyal/deepr/Deepr.sq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@ DELETE FROM LinkTags WHERE tagId = ?;
116116
updateTag:
117117
UPDATE Tags SET name = ? WHERE id = ?;
118118

119+
getTagsForLink:
120+
SELECT Tags.id,Tags.name FROM Tags INNER JOIN LinkTags ON Tags.id = LinkTags.tagId WHERE LinkTags.linkId = ? ORDER BY Tags.name;
119121

122+
hasTagLinks:
123+
SELECT COUNT(*) FROM LinkTags WHERE tagId = ?;

0 commit comments

Comments
 (0)