Skip to content

Commit 60586c9

Browse files
Isira-SeneviratneProfpatsch
authored andcommitted
Improve subscription upsert methods
1 parent 095155d commit 60586c9

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

app/src/main/java/org/schabi/newpipe/database/subscription/SubscriptionDAO.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ abstract class SubscriptionDAO : BasicDAO<SubscriptionEntity> {
9090
internal abstract fun silentInsertAllInternal(entities: List<SubscriptionEntity>): List<Long>
9191

9292
@Transaction
93-
open fun upsertAll(entities: List<SubscriptionEntity>): List<SubscriptionEntity> {
93+
open fun upsertAll(entities: List<SubscriptionEntity>) {
9494
val insertUidList = silentInsertAllInternal(entities)
9595

9696
insertUidList.forEachIndexed { index: Int, uidFromInsert: Long ->
@@ -106,7 +106,5 @@ abstract class SubscriptionDAO : BasicDAO<SubscriptionEntity> {
106106
update(entity)
107107
}
108108
}
109-
110-
return entities
111109
}
112110
}

app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,16 @@ class SubscriptionManager(context: Context) {
4848
}
4949
}
5050

51-
fun upsertAll(infoList: List<Pair<ChannelInfo, List<ChannelTabInfo>>>): List<SubscriptionEntity> {
52-
val listEntities = subscriptionTable.upsertAll(
53-
infoList.map { SubscriptionEntity.from(it.first) }
54-
)
51+
fun upsertAll(infoList: List<Pair<ChannelInfo, ChannelTabInfo>>) {
52+
val listEntities = infoList.map { SubscriptionEntity.from(it.first) }
53+
subscriptionTable.upsertAll(listEntities)
5554

5655
database.runInTransaction {
5756
infoList.forEachIndexed { index, info ->
58-
info.second.forEach {
59-
feedDatabaseManager.upsertAll(
60-
listEntities[index].uid,
61-
it.relatedItems.filterIsInstance<StreamInfoItem>()
62-
)
63-
}
57+
val streams = info.second.relatedItems.filterIsInstance<StreamInfoItem>()
58+
feedDatabaseManager.upsertAll(listEntities[index].uid, streams)
6459
}
6560
}
66-
67-
return listEntities
6861
}
6962

7063
fun updateChannelInfo(info: ChannelInfo): Completable =

app/src/main/java/org/schabi/newpipe/local/subscription/workers/SubscriptionImportWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SubscriptionImportWorker(
7777
val currentIndex = mutex.withLock { index++ }
7878
setForeground(createForegroundInfo(title, channelInfo.name, currentIndex, qty))
7979

80-
Pair(channelInfo, listOf(channelTab))
80+
Pair(channelInfo, channelTab)
8181
}
8282
}.awaitAll()
8383
}

0 commit comments

Comments
 (0)