增量人脸查询优化
This commit is contained in:
@@ -64,6 +64,8 @@ class UserViewModel : BaseViewModel() {
|
||||
private val _identifiedFoodInfoList2 = MutableStateFlow<List<FoodInfo>>(emptyList())
|
||||
val identifiedFoodInfoList2: StateFlow<List<FoodInfo>> = _identifiedFoodInfoList2
|
||||
|
||||
private var lastFaceTimestamp = 0L
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
@@ -90,14 +92,15 @@ class UserViewModel : BaseViewModel() {
|
||||
Timber.tag(TAG).d("getUserFaceCache index = $currentPageNo")
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
//获取全量数据时,时间戳改为0
|
||||
SpTool.setLastFaceTimestamp(0)
|
||||
val response = repository.getUserFaceCache(currentPageNo)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (list.isEmpty()) {
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
ToastUtils.showToast("查询人脸数据为空")
|
||||
return@withContext
|
||||
}
|
||||
@@ -108,12 +111,18 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
faceApi.updateFaceData(currentPageNo, faceEntity)
|
||||
if (list.size >= pageSize) {
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
currentPageNo++
|
||||
getUserFaceCache(currentPageNo)
|
||||
} else {
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
_loadFaceResult.value = true
|
||||
return@withContext
|
||||
}
|
||||
//查询完成所有数据,保存时间戳
|
||||
if (list.isNotEmpty()) {
|
||||
//非空最后一条数据的是时间戳,空使用上次list最后一条时间戳
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(lastFaceTimestamp)
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
|
||||
// val nextPageIndex = response.result?.nextPageIndex ?: -1
|
||||
@@ -157,7 +166,7 @@ class UserViewModel : BaseViewModel() {
|
||||
pageNo: Int = 1,
|
||||
pageSize: Int = PAGE_SIZE,
|
||||
timestamp: Long,
|
||||
onAllQueryFinished:()->Unit,
|
||||
onAllQueryFinished: () -> Unit,
|
||||
onPageQueryFinished: (List<UserFaceModel>) -> Unit
|
||||
) {
|
||||
Timber.tag(TAG).d("getFaceIncrementList")
|
||||
@@ -170,8 +179,12 @@ class UserViewModel : BaseViewModel() {
|
||||
if (parseResponse(response)) {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
return@withContext
|
||||
}
|
||||
onPageQueryFinished(list)
|
||||
if (list.size >= pageSize) {
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
getFaceIncrementList(
|
||||
pageNo = pageNo + 1,
|
||||
pageSize = pageSize,
|
||||
@@ -179,9 +192,15 @@ class UserViewModel : BaseViewModel() {
|
||||
onAllQueryFinished = onAllQueryFinished,
|
||||
onPageQueryFinished = onPageQueryFinished
|
||||
)
|
||||
} else {
|
||||
onAllQueryFinished()
|
||||
return@withContext
|
||||
}
|
||||
//查询完成所有数据,保存时间戳
|
||||
if (list.isNotEmpty()) {
|
||||
//非空实现最后一条数据的是时间戳,空使用上次list最后一条时间戳
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(lastFaceTimestamp)
|
||||
onAllQueryFinished()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user