mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+14
-10
@@ -1,3 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.builtInWebServer
|
||||
|
||||
import com.google.common.base.Function
|
||||
@@ -7,7 +8,7 @@ import com.google.common.cache.CacheLoader
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.openapi.application.Application
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.rootManager
|
||||
@@ -25,7 +26,7 @@ import com.intellij.util.io.exists
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
private val cacheSize: Long = 4096 * 4
|
||||
private const val cacheSize: Long = 4096 * 4
|
||||
|
||||
/**
|
||||
* Implement [WebServerRootsProvider] to add your provider
|
||||
@@ -34,12 +35,12 @@ class WebServerPathToFileManager(application: Application, private val project:
|
||||
val pathToInfoCache: Cache<String, PathInfo> = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterAccess(10, TimeUnit.MINUTES).build<String, PathInfo>()!!
|
||||
// time to expire should be greater than pathToFileCache
|
||||
private val virtualFileToPathInfo = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterAccess(11, TimeUnit.MINUTES).build<VirtualFile, PathInfo>()
|
||||
|
||||
|
||||
internal val pathToExistShortTermCache = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterAccess(5, TimeUnit.SECONDS).build<String, Boolean>()!!
|
||||
|
||||
/**
|
||||
* https://youtrack.jetbrains.com/issue/WEB-25900
|
||||
*
|
||||
*
|
||||
* Compute suitable roots for oldest parent (web/foo/my/file.dart -> oldest is web and we compute all suitable roots for it in advance) to avoid linear search
|
||||
* (i.e. to avoid two queries for root if files web/foo and web/bar requested if root doesn't have web dir)
|
||||
*/
|
||||
@@ -66,7 +67,7 @@ class WebServerPathToFileManager(application: Application, private val project:
|
||||
}
|
||||
suitableRoots
|
||||
}))!!
|
||||
|
||||
|
||||
init {
|
||||
application.messageBus.connect(project).subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener {
|
||||
override fun after(events: List<VFileEvent>) {
|
||||
@@ -95,7 +96,8 @@ class WebServerPathToFileManager(application: Application, private val project:
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic fun getInstance(project: Project): WebServerPathToFileManager = ServiceManager.getService(project, WebServerPathToFileManager::class.java)!!
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project) = project.service<WebServerPathToFileManager>()
|
||||
}
|
||||
|
||||
private fun clearCache() {
|
||||
@@ -105,19 +107,21 @@ class WebServerPathToFileManager(application: Application, private val project:
|
||||
parentToSuitableRoot.invalidateAll()
|
||||
}
|
||||
|
||||
@JvmOverloads fun findVirtualFile(path: String, cacheResult: Boolean = true, pathQuery: PathQuery = defaultPathQuery): VirtualFile? {
|
||||
@JvmOverloads
|
||||
fun findVirtualFile(path: String, cacheResult: Boolean = true, pathQuery: PathQuery = defaultPathQuery): VirtualFile? {
|
||||
return getPathInfo(path, cacheResult, pathQuery)?.getOrResolveVirtualFile()
|
||||
}
|
||||
|
||||
@JvmOverloads fun getPathInfo(path: String, cacheResult: Boolean = true, pathQuery: PathQuery = defaultPathQuery): PathInfo? {
|
||||
@JvmOverloads
|
||||
fun getPathInfo(path: String, cacheResult: Boolean = true, pathQuery: PathQuery = defaultPathQuery): PathInfo? {
|
||||
var pathInfo = pathToInfoCache.getIfPresent(path)
|
||||
if (pathInfo == null || !pathInfo.isValid) {
|
||||
if (pathToExistShortTermCache.getIfPresent(path) == false) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
pathInfo = doFindByRelativePath(path, pathQuery)
|
||||
if (cacheResult) {
|
||||
if (cacheResult) {
|
||||
if (pathInfo != null && pathInfo.isValid) {
|
||||
pathToInfoCache.put(path, pathInfo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user