Update an insert logic of TopicFts.

Change-Id: Id8fd51a4542e8cb22645d36ec507af4d7f02489d
pull/1268/head
Jaehwa Noh 2 days ago
parent 180dbe4c31
commit 672b4a1470

@ -54,7 +54,30 @@ internal class DefaultSearchContentsRepository @Inject constructor(
.first()
.map(PopulatedNewsResource::asFtsEntity),
)
topicFtsDao.insertAll(topicDao.getOneOffTopicEntities().map { it.asFtsEntity() })
topicDao.getOneOffTopicEntities().forEach { topicEntity ->
val topicFtsEntities = topicFtsDao.getFtsEntityById(topicEntity.id)
val size = topicFtsEntities.size
if (size == 0) {
topicFtsDao.insert(topicEntity.asFtsEntity())
return@forEach
}
if (size > 1) {
topicFtsDao.deleteById(topicEntity.id)
topicFtsDao.insert(topicEntity.asFtsEntity())
return@forEach
}
topicFtsDao.update(
name = topicEntity.name,
shortDescription = topicEntity.shortDescription,
longDescription = topicEntity.longDescription,
topicId = topicEntity.id,
)
}
}
}

Loading…
Cancel
Save