mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	Improve subscription upsert methods
This commit is contained in:
		 Isira Seneviratne
					Isira Seneviratne
				
			
				
					committed by
					
						 Profpatsch
						Profpatsch
					
				
			
			
				
	
			
			
			 Profpatsch
						Profpatsch
					
				
			
						parent
						
							095155d35f
						
					
				
				
					commit
					60586c90d6
				
			| @@ -90,7 +90,7 @@ abstract class SubscriptionDAO : BasicDAO<SubscriptionEntity> { | |||||||
|     internal abstract fun silentInsertAllInternal(entities: List<SubscriptionEntity>): List<Long> |     internal abstract fun silentInsertAllInternal(entities: List<SubscriptionEntity>): List<Long> | ||||||
|  |  | ||||||
|     @Transaction |     @Transaction | ||||||
|     open fun upsertAll(entities: List<SubscriptionEntity>): List<SubscriptionEntity> { |     open fun upsertAll(entities: List<SubscriptionEntity>) { | ||||||
|         val insertUidList = silentInsertAllInternal(entities) |         val insertUidList = silentInsertAllInternal(entities) | ||||||
|  |  | ||||||
|         insertUidList.forEachIndexed { index: Int, uidFromInsert: Long -> |         insertUidList.forEachIndexed { index: Int, uidFromInsert: Long -> | ||||||
| @@ -106,7 +106,5 @@ abstract class SubscriptionDAO : BasicDAO<SubscriptionEntity> { | |||||||
|                 update(entity) |                 update(entity) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return entities |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -48,23 +48,16 @@ class SubscriptionManager(context: Context) { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun upsertAll(infoList: List<Pair<ChannelInfo, List<ChannelTabInfo>>>): List<SubscriptionEntity> { |     fun upsertAll(infoList: List<Pair<ChannelInfo, ChannelTabInfo>>) { | ||||||
|         val listEntities = subscriptionTable.upsertAll( |         val listEntities = infoList.map { SubscriptionEntity.from(it.first) } | ||||||
|             infoList.map { SubscriptionEntity.from(it.first) } |         subscriptionTable.upsertAll(listEntities) | ||||||
|         ) |  | ||||||
|  |  | ||||||
|         database.runInTransaction { |         database.runInTransaction { | ||||||
|             infoList.forEachIndexed { index, info -> |             infoList.forEachIndexed { index, info -> | ||||||
|                 info.second.forEach { |                 val streams = info.second.relatedItems.filterIsInstance<StreamInfoItem>() | ||||||
|                     feedDatabaseManager.upsertAll( |                 feedDatabaseManager.upsertAll(listEntities[index].uid, streams) | ||||||
|                         listEntities[index].uid, |  | ||||||
|                         it.relatedItems.filterIsInstance<StreamInfoItem>() |  | ||||||
|                     ) |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return listEntities |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun updateChannelInfo(info: ChannelInfo): Completable = |     fun updateChannelInfo(info: ChannelInfo): Completable = | ||||||
|   | |||||||
| @@ -77,7 +77,7 @@ class SubscriptionImportWorker( | |||||||
|                         val currentIndex = mutex.withLock { index++ } |                         val currentIndex = mutex.withLock { index++ } | ||||||
|                         setForeground(createForegroundInfo(title, channelInfo.name, currentIndex, qty)) |                         setForeground(createForegroundInfo(title, channelInfo.name, currentIndex, qty)) | ||||||
|  |  | ||||||
|                         Pair(channelInfo, listOf(channelTab)) |                         Pair(channelInfo, channelTab) | ||||||
|                     } |                     } | ||||||
|                 }.awaitAll() |                 }.awaitAll() | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user