mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 21:41:24 +07:00
ML in SE: Use coroutines for increasing use count (IDEA-325662)
GitOrigin-RevId: e9d1f7a803eecfb76882b9e3a9f985eb56190657
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fbd8b70ca6
commit
4c3313ce55
@@ -1,17 +1,29 @@
|
||||
package com.intellij.searchEverywhereMl.ranking.features.statistician
|
||||
|
||||
import com.intellij.openapi.application.writeAction
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.statistics.StatisticsManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@Service(Service.Level.APP)
|
||||
class SearchEverywhereStatisticianService {
|
||||
class SearchEverywhereStatisticianService(private val coroutineScope: CoroutineScope) {
|
||||
companion object {
|
||||
val KEY: Key<SearchEverywhereStatistician<in Any>> = Key.create("searchEverywhere")
|
||||
}
|
||||
|
||||
fun increaseUseCount(element: Any) = getSerializedInfo(element)?.let { StatisticsManager.getInstance().incUseCount(it) }
|
||||
fun increaseUseCount(element: Any) {
|
||||
coroutineScope.launch {
|
||||
val info = getSerializedInfo(element) ?: return@launch
|
||||
val manager = StatisticsManager.getInstance()
|
||||
|
||||
writeAction {
|
||||
manager.incUseCount(info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCombinedStats(element: Any): SearchEverywhereStatisticianStats? {
|
||||
val statisticsManager = StatisticsManager.getInstance()
|
||||
|
||||
Reference in New Issue
Block a user