Skip to content

Commit 6b6a50d

Browse files
committed
cache state, only recreate when new resource is set (redhat-developer#613)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent fbedc50 commit 6b6a50d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/EditorResource.kt

+15-7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ open class EditorResource(
6262
&& !areEqual(new, existing)) {
6363
this.resource = new
6464
}
65+
setState(createState(new, state))
6566
}
6667
}
6768

@@ -94,13 +95,18 @@ open class EditorResource(
9495
*/
9596
fun getState(): EditorResourceState {
9697
return resourceChangeMutex.withLock {
97-
val state = getState(resource, state)
98-
this.state = state
99-
state
98+
val existingState = this.state
99+
if (existingState == null) {
100+
val newState = createState(resource, null)
101+
setState(newState)
102+
newState
103+
} else {
104+
existingState
105+
}
100106
}
101107
}
102108

103-
private fun getState(resource: HasMetadata, existingState: EditorResourceState?): EditorResourceState {
109+
private fun createState(resource: HasMetadata, existingState: EditorResourceState?): EditorResourceState {
104110
val isModified = isModified(resource)
105111
return when {
106112
!isConnected() ->
@@ -122,12 +128,14 @@ open class EditorResource(
122128
isOutdatedVersion()
123129
)
124130

131+
existingState is Error ->
132+
existingState
133+
125134
isOutdatedVersion() ->
126135
Outdated()
127136

128137
existingState is Pulled
129-
|| existingState is Pushed
130-
|| existingState is Error ->
138+
|| existingState is Pushed ->
131139
existingState
132140

133141
!existsOnCluster() ->
@@ -149,7 +157,7 @@ open class EditorResource(
149157
* Store resource that we tried to push but failed.
150158
* In this way this resource is not in modified state anymore
151159
* @see isModified
152-
* @see getState(resource: HasMetadata, existingState: EditorResourceState?)
160+
* @see createState(resource: HasMetadata, existingState: EditorResourceState?)
153161
*/
154162
setLastPushedPulled(resource)
155163
when {

0 commit comments

Comments
 (0)