Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ArticleRecords(
val updated = updatedAt.toEpochSecond()

database.transactionWithErrorHandling {
articleIDs.forEach { articleID ->
articleIDs.distinct().forEach { articleID ->
database.articlesQueries.upsertUnread(
articleID = articleID,
updatedAt = updated
Expand All @@ -174,7 +174,7 @@ class ArticleRecords(
val updated = updatedAt.toEpochSecond()

database.transactionWithErrorHandling {
articleIDs.forEach { articleID ->
articleIDs.distinct().forEach { articleID ->
database.articlesQueries.upsertStarred(
articleID = articleID,
updatedAt = updated
Expand Down
4 changes: 2 additions & 2 deletions capy/src/main/sqldelight/com/jocmp/capy/db/articles.sq
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ upsertUnread {
last_read_at = excluded.last_read_at,
read = excluded.read;

INSERT INTO excluded_statuses(
INSERT OR IGNORE INTO excluded_statuses(
article_id,
type
)
Expand Down Expand Up @@ -186,7 +186,7 @@ upsertStarred {
SET
starred = excluded.starred;

INSERT INTO excluded_statuses(
INSERT OR IGNORE INTO excluded_statuses(
article_id,
type
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,52 @@ class ArticleRecordsTest {
assertTrue(articleRecords.find(readArticle.id)!!.read)
}

@Test
fun markAllUnread_withDuplicateIDs() = runTest {
val articleIDs = 3.repeated { RandomUUID.generate() }
val readArticle = articleFixture.create(read = false)

articleIDs.forEach { id ->
articleFixture.create(id = id, read = true)
}

articleRecords.markAllUnread(articleIDs + articleIDs.first())

val articles = articleIDs.map { articleRecords.find(it)!! }

assertTrue(articles.none { it.read })
assertTrue(articleRecords.find(readArticle.id)!!.read)
}

@Test
fun markAllStarred_withDuplicateIDs() = runTest {
val articleIDs = 3.repeated { RandomUUID.generate() }

articleIDs.forEach { id ->
articleFixture.create(id = id)
}

articleRecords.markAllStarred(articleIDs + articleIDs.first())

val articles = articleIDs.map { articleRecords.find(it)!! }

assertTrue(articles.all { it.starred })
}

@Test
fun upsertUnread_ignoresRepeatedMarkers() = runTest {
val article = articleFixture.create(read = true)
val updatedAt = nowUTC().toEpochSecond()

database.transaction {
database.articlesQueries.upsertUnread(articleID = article.id, updatedAt = updatedAt)
database.articlesQueries.upsertUnread(articleID = article.id, updatedAt = updatedAt)
database.articlesQueries.updateStaleUnreads()
}

assertFalse(articleRecords.find(article.id)!!.read)
}

@Test
fun deleteOldArticles() = runTest {
val oldPublishedAt = nowUTC().minusMonths(4).toEpochSecond()
Expand Down
Loading