Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions app/src/main/java/app/gamenative/data/SteamLicenseForPics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.gamenative.data

import androidx.room.ColumnInfo

// Slimmed down type for retrieving licences for processing.
data class SteamLicenseForPics(
val packageId: Int,
@ColumnInfo("access_token")
val accessToken: Long,
)
4 changes: 4 additions & 0 deletions app/src/main/java/app/gamenative/db/dao/SteamLicenseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import app.gamenative.data.SteamLicense
import app.gamenative.data.SteamLicenseForPics
import kotlin.math.min

val SQLITE_MAX_VARS = 999
Expand All @@ -29,6 +30,9 @@ interface SteamLicenseDao {
@Query("SELECT * FROM steam_license")
suspend fun getAllLicenses(): List<SteamLicense>

@Query("SELECT packageId, access_token FROM steam_license")
suspend fun getLicensesForPics(): List<SteamLicenseForPics>

@Query("SELECT * FROM steam_license WHERE packageId = :packageId")
suspend fun findLicense(packageId: Int): SteamLicense?

Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/app/gamenative/service/SteamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import app.gamenative.data.GameSource
import app.gamenative.data.LaunchInfo
import app.gamenative.data.OwnedGames
import app.gamenative.data.PostSyncInfo
import app.gamenative.data.SteamLicenseForPics
import app.gamenative.data.SteamApp
import app.gamenative.data.SteamControllerConfigDetail
import app.gamenative.data.SteamFriend
Expand Down Expand Up @@ -4137,7 +4138,7 @@ class SteamService : Service(), IChallengeUrlChanged {
// Chunk the input to reduce memory pressures for very large items.
licenses = callback.licenseList
cachedLicenseDao.deleteAll()
callback.licenseList.chunked(500).forEach { chunk ->
callback.licenseList.chunked(MAX_PICS_BUFFER).forEach { chunk ->
cachedLicenseDao.insertAll(
chunk.map { license ->
CachedLicense(licenseJson = LicenseSerializer.serializeLicense(license))
Expand Down Expand Up @@ -4176,22 +4177,26 @@ class SteamService : Service(), IChallengeUrlChanged {

if (licensesToAdd.isNotEmpty()) {
Timber.i("Adding ${licensesToAdd.size} licenses")
licensesToAdd.chunked(500).forEach { chunk ->
licensesToAdd.chunked(MAX_PICS_BUFFER).forEach { chunk ->
licenseDao.insertAll(chunk)
}
}

Timber.i("Finished adding ${licensesToAdd.size} licenses")

val licensesToRemove = licenseDao.findStaleLicences(
packageIds = callback.licenseList.map { it.packageID },
)

if (licensesToRemove.isNotEmpty()) {
Timber.i("Removing ${licensesToRemove.size} (stale) licenses")
val packageIds = licensesToRemove.map { it.packageId }
licenseDao.deleteStaleLicenses(packageIds)
}

Timber.i("Getting licences from DB")
Comment thread
phobos665 marked this conversation as resolved.
Outdated
// Get PICS information with the current license database.
licenseDao.getAllLicenses()
licenseDao.getLicensesForPics()
.map { PICSRequest(it.packageId, it.accessToken) }
.chunked(MAX_PICS_BUFFER)
.forEach { chunk ->
Expand Down
Loading