leandro
09/29/2021, 5:47 PMkpgalligan
09/29/2021, 6:23 PMleandro
09/29/2021, 7:31 PMtoKotlin
on the codebase. Here’s the insert function of SqlMilestoneStore:
suspend fun insert(milestones: List<Milestone>): Unit = withContext(context) {
val time = measureTime {
milestoneQueries.transaction {
milestones.forEach { milestone ->
milestoneQueries.insert(
achievementId = milestone.achievementId,
progress = milestone.progress,
achievedAt = milestone.achievedAt,
celebratedAt = milestone.celebratedAt,
)
}
}
}
// TODO integrate Kermit
//Timber.d("[Profiler] Inserted ${milestones.size} milestones in ${time}ms.")
}
The context is Dispatchers.Default
,
On Swift we’re calling it like:
func saveMilestones(_ milestones: [CelebratedMilestone]) {
milestoneStore.insert(milestones: milestones.map { Milestone(achievementId: $0.achievementId,
progress: 100,
achievedAt: nil,
celebratedAt: $0.celebratedAt) }) { _, error in }
}
that’s on the main threadkpgalligan
10/01/2021, 3:28 PMkpgalligan
10/01/2021, 3:32 PMtoKotlin
is maybe coming from K/N and integrating iOS objects. My (wild) guess is somehow the state in the milestones: List<Milestone>
isn't transitively frozen. Going through withContext(context)
should freeze that lambda and all state captured within. If Milestone is an iOS extension of some type, maybe that's hiding the freeze call? That's a weird one, though. I'd have to play with it.leandro
10/02/2021, 11:59 AMMilestone
(and CelebratedMilestone
are actually sqldelight’s model from the milestone table, from a different projections. It creates the these entities like so:
class Foo: ViewController {
private var listOfASqlDelightModel = //
func markAsCelebrated(items: [ASqlDelightModel]) {
let celebratedAt = Date()
milestoneDataSource.saveMilestones(items.map({ item in
CelebratedMilestone(item, celebratedAt: celebratedAt)
}))
}
func save() {
markAsCeleberated(items: listOfASqlDelightModel)
}
}
i guess it freezes the lambda inside markAsCelebrated(items:)
. Hopefully not too confusing. But trying to funnel down it is sketchy that var
property declared and it seems to be the issue. Does it make sense? I’m looking at this for so long that I’m biased and mentally tired.leandro
10/02/2021, 12:31 PM