settings-sync: simplify: use a variable instead of a map, since there is only one...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Sun, 26 Jun 2022 14:52:08 +0000 (15:52 +0100)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Sun, 26 Jun 2022 15:50:03 +0000 (15:50 +0000)
GitOrigin-RevId: 6c85e8d2672237fb93ddcf13f897e5ccbbc5c78d

plugins/settings-sync/src/com/intellij/settingsSync/CloudConfigServerCommunicator.kt

index 9eed5b187feb24cd28c6dc61317f84d48b472b82..fb8dfe09e3cae620b583821cebc2af56f9a5c3bb 100644 (file)
@@ -26,10 +26,10 @@ internal class CloudConfigServerCommunicator : SettingsSyncRemoteCommunicator {
 
   private val client get() = _client.value
   private val _client = lazy { createCloudConfigClient(clientVersionContext) }
-
-  private val currentVersionOfFiles = mutableMapOf<String, String>() // todo persist this information
   private val clientVersionContext = CloudConfigVersionContext()
 
+  private var knownVersionOfSnapshotZip : String? = null
+
   private fun receiveSnapshotFile(): InputStream? {
     return clientVersionContext.doWithVersion(null) {
       val result = client.read(SETTINGS_SYNC_SNAPSHOT_ZIP)
@@ -38,13 +38,14 @@ internal class CloudConfigServerCommunicator : SettingsSyncRemoteCommunicator {
     }
   }
 
+  // executed under the lock of the VersionContext
   private fun rememberLatestVersion() {
     val actualVersion: String? = clientVersionContext.get(SETTINGS_SYNC_SNAPSHOT_ZIP)
     if (actualVersion == null) {
       LOG.warn("Version not stored in the context for $SETTINGS_SYNC_SNAPSHOT_ZIP")
     }
     else {
-      currentVersionOfFiles[SETTINGS_SYNC_SNAPSHOT_ZIP] = actualVersion
+      knownVersionOfSnapshotZip = actualVersion
     }
   }
 
@@ -55,7 +56,7 @@ internal class CloudConfigServerCommunicator : SettingsSyncRemoteCommunicator {
       versionToPush = getLatestVersion()?.versionId
     }
     else {
-      val rememberedVersion = currentVersionOfFiles[SETTINGS_SYNC_SNAPSHOT_ZIP]
+      val rememberedVersion = knownVersionOfSnapshotZip
       if (rememberedVersion != null) {
         versionToPush = rememberedVersion
       }
@@ -87,7 +88,7 @@ internal class CloudConfigServerCommunicator : SettingsSyncRemoteCommunicator {
       LOG.info("Latest version info: $latestVersion")
       when (latestVersion?.versionId) {
         null -> return ServerState.FileNotExists
-        currentVersionOfFiles[SETTINGS_SYNC_SNAPSHOT_ZIP] -> return ServerState.UpToDate
+        knownVersionOfSnapshotZip -> return ServerState.UpToDate
         else -> return ServerState.UpdateNeeded
       }
     }
@@ -184,7 +185,7 @@ internal class CloudConfigServerCommunicator : SettingsSyncRemoteCommunicator {
 
   @Throws(IOException::class)
   override fun delete() {
-    currentVersionOfFiles.remove(SETTINGS_SYNC_SNAPSHOT_ZIP)
+    knownVersionOfSnapshotZip = null
     client.delete(SETTINGS_SYNC_SNAPSHOT_ZIP)
   }