mirror of https://github.com/readrops/Readrops.git
Improve Nextcloud News updateFeed performance
This commit is contained in:
parent
85b830b82b
commit
49fc62edc2
|
@ -52,10 +52,10 @@ interface NewNextcloudNewsService {
|
||||||
@DELETE("feeds/{feedId}")
|
@DELETE("feeds/{feedId}")
|
||||||
suspend fun deleteFeed(@Path("feedId") feedId: Int)
|
suspend fun deleteFeed(@Path("feedId") feedId: Int)
|
||||||
|
|
||||||
@PUT("feeds/{feedId}/move")
|
@POST("feeds/{feedId}/move")
|
||||||
suspend fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map<String, Int?>)
|
suspend fun changeFeedFolder(@Path("feedId") feedId: Int, @Body folderIdMap: Map<String, Int?>)
|
||||||
|
|
||||||
@PUT("feeds/{feedId}/rename")
|
@POST("feeds/{feedId}/rename")
|
||||||
suspend fun renameFeed(@Path("feedId") feedId: Int, @Body feedTitleMap: Map<String, String>)
|
suspend fun renameFeed(@Path("feedId") feedId: Int, @Body feedTitleMap: Map<String, String>)
|
||||||
|
|
||||||
@POST("folders")
|
@POST("folders")
|
||||||
|
|
|
@ -12,6 +12,11 @@ import com.readrops.db.entities.Feed
|
||||||
import com.readrops.db.entities.Folder
|
import com.readrops.db.entities.Folder
|
||||||
import com.readrops.db.entities.Item
|
import com.readrops.db.entities.Item
|
||||||
import com.readrops.db.entities.account.Account
|
import com.readrops.db.entities.account.Account
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
|
@ -19,7 +24,8 @@ import org.koin.core.component.get
|
||||||
class NextcloudNewsRepository(
|
class NextcloudNewsRepository(
|
||||||
database: Database,
|
database: Database,
|
||||||
account: Account,
|
account: Account,
|
||||||
private val dataSource: NewNextcloudNewsDataSource
|
private val dataSource: NewNextcloudNewsDataSource,
|
||||||
|
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
) : BaseRepository(database, account), KoinComponent {
|
) : BaseRepository(database, account), KoinComponent {
|
||||||
|
|
||||||
override suspend fun login(account: Account) {
|
override suspend fun login(account: Account) {
|
||||||
|
@ -95,12 +101,14 @@ class NextcloudNewsRepository(
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateFeed(feed: Feed) {
|
override suspend fun updateFeed(feed: Feed) = withContext(dispatcher) {
|
||||||
val folder =
|
val folder =
|
||||||
if (feed.folderId != null) database.folderDao().select(feed.folderId!!) else null
|
if (feed.folderId != null) database.folderDao().select(feed.folderId!!) else null
|
||||||
|
|
||||||
dataSource.renameFeed(feed.name!!, feed.remoteId!!.toInt())
|
listOf(
|
||||||
dataSource.changeFeedFolder(folder?.remoteId?.toInt(), feed.remoteId!!.toInt())
|
async { dataSource.renameFeed(feed.name!!, feed.remoteId!!.toInt()) },
|
||||||
|
async { dataSource.changeFeedFolder(folder?.remoteId?.toInt(), feed.remoteId!!.toInt()) }
|
||||||
|
).awaitAll()
|
||||||
|
|
||||||
super.updateFeed(feed)
|
super.updateFeed(feed)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue