+
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 @@ -13,6 +13,7 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import java.time.Instant
import javax.inject.Singleton
import me.vanpetegem.accentor.data.albums.AlbumDao
import me.vanpetegem.accentor.data.albums.DbAlbum
import me.vanpetegem.accentor.data.albums.DbAlbumArtist
Expand Down Expand Up @@ -64,6 +65,7 @@ abstract class AccentorDatabase : RoomDatabase() {
@InstallIn(SingletonComponent::class)
internal object DatabaseModule {
@Provides
@Singleton
fun provideAccentorDatabase(@ApplicationContext context: Context): AccentorDatabase {
return Room.databaseBuilder(
context.applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,27 @@ class AlbumRepository @Inject constructor(
suspend fun refresh(handler: suspend (Result<Unit>) -> Unit) {
val fetchStart = Instant.now()

var toUpsert = ArrayList<Album>()
var count = 0
for (result in index(authenticationRepository.server.value!!, authenticationRepository.authData.value!!)) {
when (result) {
is Result.Success -> {
val fetchTime = Instant.now()
albumDao.upsertAll(result.data.map { Album.fromApi(it, fetchTime) })
toUpsert.addAll(result.data.map { Album.fromApi(it, fetchTime) })
count += 1
if (count >= 5) {
albumDao.upsertAll(toUpsert)
toUpsert.clear()
count = 0
}
}
is Result.Error -> {
handler(Result.Error(result.exception))
return
}
}
}
albumDao.upsertAll(toUpsert)
albumDao.deleteFetchedBefore(fetchStart)
handler(Result.Success(Unit))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,27 @@ class ArtistRepository @Inject constructor(
suspend fun refresh(handler: suspend (Result<Unit>) -> Unit) {
val fetchStart = Instant.now()

var toUpsert = ArrayList<Artist>()
var count = 0
for (result in index(authenticationRepository.server.value!!, authenticationRepository.authData.value!!)) {
when (result) {
is Result.Success -> {
val fetchTime = Instant.now()
artistDao.upsertAll(result.data.map { Artist.fromApi(it, fetchTime) })
toUpsert.addAll(result.data.map { Artist.fromApi(it, fetchTime) })
count += 1
if (count >= 5) {
artistDao.upsertAll(toUpsert)
toUpsert.clear()
count = 0
}
}
is Result.Error -> {
handler(Result.Error(result.exception))
return
}
}
}
artistDao.upsertAll(toUpsert)
artistDao.deleteFetchedBefore(fetchStart)
handler(Result.Success(Unit))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ class PlayRepository @Inject constructor(
suspend fun refresh(handler: suspend (Result<Unit>) -> Unit) {
val fetchStart = Instant.now()

var toUpsert = ArrayList<Play>()
var count = 0
for (result in index(authenticationRepository.server.value!!, authenticationRepository.authData.value!!)) {
when (result) {
is Result.Success -> {
val fetchTime = Instant.now()
playDao.upsertAll(result.data.map { Play.fromApi(it, fetchTime) })
toUpsert.addAll(result.data.map { Play.fromApi(it, fetchTime) })
count += 1
if (count >= 5) {
playDao.upsertAll(toUpsert)
toUpsert.clear()
count = 0
}
}
is Result.Error -> {
handler(Result.Error(result.exception))
return
}
}
}
playDao.upsertAll(toUpsert)
playDao.deleteFetchedBefore(fetchStart)
handler(Result.Success(Unit))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@ class TrackRepository @Inject constructor(

suspend fun refresh(handler: suspend (Result<Unit>) -> Unit) {
val fetchStart = Instant.now()

var toUpsert = ArrayList<Track>()
var count = 0
for (result in index(authenticationRepository.server.value!!, authenticationRepository.authData.value!!)) {
when (result) {
is Result.Success -> {
val fetchTime = Instant.now()
trackDao.upsertAll(result.data.map { Track.fromApi(it, fetchTime) })
toUpsert.addAll(result.data.map { Track.fromApi(it, fetchTime) })
count += 1
if (count >= 5) {
trackDao.upsertAll(toUpsert)
toUpsert.clear()
count = 0
}
}
is Result.Error -> {
handler(Result.Error(result.exception))
return
}
}
}
trackDao.upsertAll(toUpsert)
trackDao.deleteFetchedBefore(fetchStart)
handler(Result.Success(Unit))
}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载