Skip to content

Commit bd3c863

Browse files
authored
fix: Fix project cache size always showing as zero in settings (#1204)
1 parent 8cdf19b commit bd3c863

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ src/main/resources/META-INF/services/com.itangcent.common.spi.SetupAble
4444
/envs
4545
out/
4646

47+
plugin-adapter/build/
4748
plugin-adapter/plugin-adapter-markdown/build/
4849
gradle/wrapper/caches
4950
gradle/wrapper/daemon

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.itangcent.common.logger.Log
1111
import com.itangcent.common.utils.*
1212
import com.itangcent.idea.icons.EasyIcons
1313
import com.itangcent.idea.icons.iconOnly
14+
import com.itangcent.idea.plugin.api.cache.ProjectCacheRepository
1415
import com.itangcent.idea.plugin.api.export.postman.PostmanCachedApiHelper
1516
import com.itangcent.idea.plugin.api.export.postman.PostmanUrls.INTEGRATIONS_DASHBOARD
1617
import com.itangcent.idea.plugin.api.export.postman.PostmanWorkspace
@@ -27,6 +28,8 @@ import com.itangcent.idea.utils.Charsets
2728
import com.itangcent.idea.utils.SwingUtils
2829
import com.itangcent.idea.utils.isDoubleClick
2930
import com.itangcent.intellij.context.ActionContext
31+
import com.itangcent.intellij.file.DefaultLocalFileRepository
32+
import com.itangcent.intellij.file.LocalFileRepository
3033
import com.itangcent.intellij.logger.Logger
3134
import java.awt.event.MouseAdapter
3235
import java.awt.event.MouseEvent
@@ -448,37 +451,37 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
448451
}
449452

450453
private fun computeProjectCacheSize() {
451-
val currentProject = myProject ?: return
452-
val projectBasePath = currentProject.basePath
453-
val cachePath = "$projectBasePath${File.separator}.idea${File.separator}.cache${File.separator}$basePath"
454+
val cachePath = actionContext.instance(ProjectCacheRepository::class).cachePath()
454455
val cacheSize = computeFolderSize(cachePath)
455456
actionContext.runInSwingUI {
456457
this.projectCacheSizeLabel!!.text = StringUtil.formatFileSize(cacheSize)
457458
}
458459
}
459460

460461
private fun clearProjectCache() {
461-
val currentProject = myProject ?: return
462-
val projectBasePath = currentProject.basePath
463-
val cachePath = "$projectBasePath${File.separator}.idea${File.separator}.cache${File.separator}$basePath"
462+
val cachePath = actionContext.instance(ProjectCacheRepository::class).cachePath()
464463
deleteFolder(cachePath)
465464
computeProjectCacheSize()
466465
}
467466

468467
private fun computeGlobalCacheSize() {
469-
val cachePath = "${globalBasePath()}${File.separator}$basePath"
468+
val cachePath = actionContext.instance(DefaultLocalFileRepository::class).cachePath()
470469
val cacheSize = computeFolderSize(cachePath)
471470
actionContext.runInSwingUI {
472471
this.globalCacheSizeLabel!!.text = StringUtil.formatFileSize(cacheSize)
473472
}
474473
}
475474

476475
private fun clearGlobalCache() {
477-
val cachePath = "${globalBasePath()}${File.separator}$basePath"
476+
val cachePath = actionContext.instance(DefaultLocalFileRepository::class).cachePath()
478477
deleteFolder(cachePath)
479478
computeGlobalCacheSize()
480479
}
481480

481+
private fun LocalFileRepository.cachePath(): String {
482+
return this.getOrCreateFile(".setting.size").parentFile.path
483+
}
484+
482485
private fun computeFolderSize(path: String): Long {
483486
val file = File(path)
484487
if (file.exists()) {
@@ -505,15 +508,6 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
505508
settings.setPostmanCollectionsPairs(pairs)
506509
}
507510

508-
private fun globalBasePath(): String {
509-
510-
var home = SystemUtils.userHome
511-
if (home.endsWith(File.separator)) {
512-
home = home.substring(0, home.length - 1)
513-
}
514-
return home
515-
}
516-
517511
private class PostmanWorkspaceData {
518512

519513
var id: String?
@@ -630,8 +624,6 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
630624
}
631625

632626
companion object : Log() {
633-
const val basePath = ".easy_api"
634-
635627
const val setting_path = "easy.api.setting.path"
636628

637629
private var DEFAULT_WORKSPACE = PostmanWorkspaceData(null, "")

0 commit comments

Comments
 (0)