Skip to content

Commit 6b10341

Browse files
authored
Merge pull request #2397 from digma-ai/remove-unused-properties-from-PersistenceState
remove-unused-properties-from-PersistenceState Closes #2390
2 parents 89173af + 7b6294a commit 6b10341

File tree

12 files changed

+46
-123
lines changed

12 files changed

+46
-123
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/docker/DockerService.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ class DockerService {
7676

7777

7878
fun isEngineInstalled(): Boolean {
79-
return PersistenceService.getInstance().isLocalEngineInstalled() != null &&
80-
PersistenceService.getInstance().isLocalEngineInstalled() == true
79+
return PersistenceService.getInstance().isLocalEngineInstalled()
8180
}
8281

8382

@@ -373,7 +372,7 @@ class DockerService {
373372
project,
374373
"Please make sure the Docker daemon is running\n" +
375374
"Once the Docker daemon is running, press the retry button.\n",
376-
"Digma engine failed to run",
375+
"Digma Engine Failed to Run",
377376
"Retry",
378377
"Cancel",
379378
null

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceData.kt

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,9 @@ import java.time.Instant
66

77
internal data class PersistenceData(
88

9-
10-
//todo: some flags where initially Booleans, after a while we needed the timestamp too.
11-
// so a timestamp is added and should replace the Boolean, no need to a boolean instead check the timestamp for
12-
// null. these booleans can be removed after some time when all users already updated. probably waiting two months
13-
// is enough. for new users only the timestamp will be used.
14-
15-
169
var latestSelectedEnvId: String? = null,
17-
var isWorkspaceOnly: Boolean = false,
18-
//todo: we want to change the name to isObservabilityEnabled.
19-
// remove isAutoOtel after some versions, can remove in June 2024 when probably all users updated the plugin
20-
var isAutoOtel: Boolean = true,
2110
var isObservabilityEnabled: Boolean = true,
2211
var firstWizardLaunch: Boolean = true,
23-
24-
2512
var userEmail: String? = null,
2613
var userRegistrationEmail: String? = null,
2714
var isLocalEngineInstalled: Boolean? = null,
@@ -33,39 +20,25 @@ internal data class PersistenceData(
3320

3421
var noInsightsYetNotificationPassed: Boolean = false,
3522

36-
//notificationsStartDate is different from other timestamps in that it needs to be same format and
37-
// timezone as in the backend
38-
var notificationsStartDate: String? = null,
39-
40-
var pendingEnvironment: String? = null,
41-
42-
//todo: remove firstTimeAssetsReceived in May 2024
43-
var firstTimeAssetsReceived: Boolean = false,
4423
@OptionTag(converter = InstantConverter::class)
4524
var firstTimeAssetsReceivedTimestamp: Instant? = null,
4625

47-
//todo: remove firstTimeConnectionEstablished and firstTimeConnectionEstablishedTimestamp in May 2024
48-
// and rename firstTimeConnectionEstablishedTimestampNew to firstTimeConnectionEstablishedTimestamp
49-
var firstTimeConnectionEstablished: Boolean = false,
50-
var firstTimeConnectionEstablishedTimestamp: String? = null,
26+
//todo: backwards compatibility, remove firstTimeConnectionEstablishedTimestampNew in January 2025
27+
// renamed without the new suffix
5128
@OptionTag(converter = InstantConverter::class)
5229
var firstTimeConnectionEstablishedTimestampNew: Instant? = null,
30+
@OptionTag(converter = InstantConverter::class)
31+
var firstTimeConnectionEstablishedTimestamp: Instant? = null,
5332

54-
//todo: remove firstTimeInsightReceived in May 2024
55-
var firstTimeInsightReceived: Boolean = false,
5633
@OptionTag(converter = InstantConverter::class)
5734
var firstTimeInsightReceivedTimestamp: Instant? = null,
5835

59-
//todo: remove firstTimeRecentActivityReceived in May 2024
60-
var firstTimeRecentActivityReceived: Boolean = false,
6136
@OptionTag(converter = InstantConverter::class)
6237
var firstTimeRecentActivityReceivedTimestamp: Instant? = null,
6338

6439
@OptionTag(converter = InstantConverter::class)
6540
var firstTimePluginLoadedTimestamp: Instant? = null,
6641

67-
//todo: remove firstTimePerformanceMetrics in May 2024
68-
var firstTimePerformanceMetrics: Boolean = false,
6942
@OptionTag(converter = InstantConverter::class)
7043
var firstTimePerformanceMetricsTimestamp: Instant? = null,
7144

@@ -86,6 +59,7 @@ internal data class PersistenceData(
8659

8760
var isFinishDigmathonGameForUser: Boolean = false,
8861
var digmathonViewedInsights: String? = null,
62+
8963
@OptionTag(converter = InstantConverter::class)
9064
var digmathonViewedInsightsLastUpdated: Instant? = null,
9165
var digmathonStartedForUser: Boolean = false

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceService.kt

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.digma.intellij.plugin.persistence
22

33
import com.intellij.openapi.components.Service
44
import com.intellij.openapi.components.service
5-
import org.digma.intellij.plugin.common.DatesUtils
65
import java.time.Instant
76

87

@@ -42,8 +41,8 @@ class PersistenceService {
4241
return state.firstWizardLaunch
4342
}
4443

45-
fun isLocalEngineInstalled(): Boolean? {
46-
return state.isLocalEngineInstalled
44+
fun isLocalEngineInstalled(): Boolean {
45+
return state.isLocalEngineInstalled ?: false
4746
}
4847

4948
fun setLocalEngineInstalled(isInstalled: Boolean) {
@@ -54,16 +53,11 @@ class PersistenceService {
5453
return state.userEmail != null || state.userRegistrationEmail != null
5554
}
5655

57-
fun isFirstTimeAssetsReceived(): Boolean {
58-
//todo: backwards compatibility, remove state.firstTimeAssetsReceived on May 2024
59-
if (state.firstTimeAssetsReceived && state.firstTimeAssetsReceivedTimestamp == null) {
60-
state.firstTimeAssetsReceivedTimestamp = Instant.now()
61-
}
62-
56+
fun isFirstAssetsReceived(): Boolean {
6357
return state.firstTimeAssetsReceivedTimestamp != null
6458
}
6559

66-
fun setFirstTimeAssetsReceived() {
60+
fun setFirstAssetsReceived() {
6761
state.firstTimeAssetsReceivedTimestamp = Instant.now()
6862
}
6963

@@ -84,86 +78,51 @@ class PersistenceService {
8478
}
8579

8680
fun isFirstTimePerformanceMetrics(): Boolean {
87-
//todo: backwards compatibility, remove state.firstTimePerformanceMetrics on May 2024
88-
if (state.firstTimePerformanceMetrics && state.firstTimePerformanceMetricsTimestamp == null) {
89-
state.firstTimePerformanceMetricsTimestamp = Instant.now()
90-
}
91-
92-
return state.firstTimePerformanceMetricsTimestamp != null
81+
return state.firstTimePerformanceMetricsTimestamp == null
9382
}
9483

95-
fun setFirstTimePerformanceMetrics() {
84+
fun setFirstTimePerformanceMetricsDone() {
9685
state.firstTimePerformanceMetricsTimestamp = Instant.now()
9786
}
9887

9988

100-
fun isFirstTimeInsightReceived(): Boolean {
101-
//todo: backwards compatibility, remove state.firstTimeInsightReceived on May 2024
102-
if (state.firstTimeInsightReceived && state.firstTimeInsightReceivedTimestamp == null) {
103-
state.firstTimeInsightReceivedTimestamp = Instant.now()
104-
}
105-
89+
fun isFirstInsightReceived(): Boolean {
10690
return state.firstTimeInsightReceivedTimestamp != null
10791
}
10892

109-
fun setFirstTimeInsightReceived() {
93+
fun setFirstInsightReceived() {
11094
state.firstTimeInsightReceivedTimestamp = Instant.now()
11195
}
11296

11397

114-
fun isFirstTimeRecentActivityReceived(): Boolean {
115-
//todo: backwards compatibility, remove state.firstTimeRecentActivityReceived on May 2024
116-
if (state.firstTimeRecentActivityReceived && state.firstTimeRecentActivityReceivedTimestamp == null) {
117-
state.firstTimeRecentActivityReceivedTimestamp = Instant.now()
118-
}
119-
98+
fun isFirstRecentActivityReceived(): Boolean {
12099
return state.firstTimeRecentActivityReceivedTimestamp != null
121100
}
122101

123-
fun setFirstTimeRecentActivityReceived() {
102+
fun setFirstRecentActivityReceived() {
124103
state.firstTimeRecentActivityReceivedTimestamp = Instant.now()
125104
}
126105

127106

128-
fun isWorkspaceOnly(): Boolean {
129-
return state.isWorkspaceOnly
130-
}
131-
132-
fun setWorkspaceOnly(isWorkspaceOnly: Boolean) {
133-
state.isWorkspaceOnly = isWorkspaceOnly
134-
}
135-
136107
fun isObservabilityEnabled(): Boolean {
137108
return state.isObservabilityEnabled
138109
}
139110

140111
fun setObservabilityEnabled(isObservabilityEnabled: Boolean) {
141112
state.isObservabilityEnabled = isObservabilityEnabled
142-
//todo: remove isAutoOtel on June 2024
143-
state.isAutoOtel = isObservabilityEnabled
144113
}
145114

146115

147-
148116
fun isFirstTimeConnectionEstablished(): Boolean {
149-
//todo: backwards compatibility, remove state.firstTimeConnectionEstablished and
150-
// state.firstTimeConnectionEstablishedTimestamp on May 2024
151-
if (state.firstTimeConnectionEstablished && state.firstTimeConnectionEstablishedTimestampNew == null) {
152-
val instant = state.firstTimeConnectionEstablishedTimestamp?.let {
153-
DatesUtils.Instants.stringToInstant(it)
154-
} ?: Instant.now()
155-
state.firstTimeConnectionEstablishedTimestampNew = instant
156-
}
157-
158-
return state.firstTimeConnectionEstablishedTimestampNew != null
117+
return state.firstTimeConnectionEstablishedTimestamp != null
159118
}
160119

161120
fun setFirstTimeConnectionEstablished() {
162-
state.firstTimeConnectionEstablishedTimestampNew = Instant.now()
121+
state.firstTimeConnectionEstablishedTimestamp = Instant.now()
163122
}
164123

165124
fun getFirstTimeConnectionEstablishedTimestamp(): Instant? {
166-
return state.firstTimeConnectionEstablishedTimestampNew
125+
return state.firstTimeConnectionEstablishedTimestamp
167126
}
168127

169128

@@ -220,16 +179,6 @@ class PersistenceService {
220179
state.noInsightsYetNotificationPassed = true
221180
}
222181

223-
224-
fun getNotificationsStartDate(): String? {
225-
return state.notificationsStartDate
226-
}
227-
228-
fun setNotificationsStartDate(notificationsStartDate: String) {
229-
state.notificationsStartDate = notificationsStartDate
230-
}
231-
232-
233182
fun updateLastConnectionTimestamp() {
234183
state.lastConnectionTimestamp = Instant.now()
235184
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceState.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ internal open class PersistenceState : PersistentStateComponent<PersistenceData>
3131
override fun loadState(state: PersistenceData) {
3232
myPersistenceData = state
3333

34-
//todo: backwards compatibility, we want to change the name to isObservabilityEnabled.
35-
// remove isAutoOtel after some versions, can remove in June 2024 when probably all users updated the plugin
36-
myPersistenceData.isObservabilityEnabled = myPersistenceData.isAutoOtel
34+
//todo: backwards compatibility, remove firstTimeConnectionEstablishedTimestampNew in January 2025
35+
// renamed without the new suffix
36+
myPersistenceData.firstTimeConnectionEstablishedTimestamp = myPersistenceData.firstTimeConnectionEstablishedTimestampNew
3737
}
3838

3939

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/ActivityMonitor.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
160160

161161
val mutableDetails = details.toMutableMap()
162162

163-
mutableDetails["firstTimeInsightReceived"] = PersistenceService.getInstance().isFirstTimeInsightReceived()
164-
mutableDetails["firstTimeAssetsReceived"] = PersistenceService.getInstance().isFirstTimeAssetsReceived()
165-
mutableDetails["firstTimeRecentActivityReceived"] = PersistenceService.getInstance().isFirstTimeRecentActivityReceived()
163+
mutableDetails["firstTimeInsightReceived"] = PersistenceService.getInstance().isFirstInsightReceived()
164+
mutableDetails["firstTimeAssetsReceived"] = PersistenceService.getInstance().isFirstAssetsReceived()
165+
mutableDetails["firstTimeRecentActivityReceived"] = PersistenceService.getInstance().isFirstRecentActivityReceived()
166166
mutableDetails["plugin.version"] = SemanticVersionUtil.getPluginVersionWithoutBuildNumberAndPreRelease("unknown")
167167
mutableDetails["ide.version"] = ApplicationInfo.getInstance().fullVersion
168168
mutableDetails["ide.name"] = ApplicationInfo.getInstance().versionName
@@ -254,7 +254,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
254254
private fun registerOnlineOfflineUserAction(details: Map<String, Any>) {
255255

256256
val eventName =
257-
if (PersistenceService.getInstance().isFirstTimeAssetsReceived() && BackendConnectionMonitor.getInstance(project).isConnectionOk()) {
257+
if (PersistenceService.getInstance().isFirstAssetsReceived() && BackendConnectionMonitor.getInstance(project).isConnectionOk()) {
258258
"online-user-action"
259259
} else {
260260
"offline-user-action"
@@ -313,7 +313,8 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
313313
}
314314

315315
fun registerFirstInsightReceived() {
316-
capture("insight first-received")
316+
capture("insight first-received") //todo: fix dashboards to use 'plugin first-insight' and remove this one
317+
capture("plugin first-insight") //use this so it's the same pattern as "plugin first-assets" and "plugin first-activity"
317318
}
318319

319320
fun registerFirstAssetsReceived() {

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/PerformanceMetricsPosthogEventStartupActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ class ContinuousPerformanceMetricsReporter : DisposableAdaptor {
4848

4949
Log.log(logger::info, "ContinuousPerformanceMetricsReporter starting")
5050

51-
if (!PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
51+
if (PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
5252

5353
val disposable = Disposer.newDisposable()
5454
disposable.disposingPeriodicTask(
5555
"ContinuousPerformanceMetricsReporter.waitForFirstTime",
5656
2.minutes.inWholeMilliseconds,
5757
10.minutes.inWholeMilliseconds, true
5858
) {
59-
if (!PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
59+
if (PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
6060
checkForFirstTime()
6161
} else {
6262
//will dispose this task
@@ -73,7 +73,7 @@ class ContinuousPerformanceMetricsReporter : DisposableAdaptor {
7373

7474
private fun checkForFirstTime() {
7575

76-
if (!PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
76+
if (PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
7777
try {
7878

7979
findActiveProject()?.takeIf { isProjectValid(it) }?.let { project ->
@@ -85,8 +85,8 @@ class ContinuousPerformanceMetricsReporter : DisposableAdaptor {
8585
getActivityMonitor(project).let { activityMonitor ->
8686
Log.log(logger::info, "registering first time performance metrics")
8787
activityMonitor.registerPerformanceMetrics(result, true)
88-
if (!PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
89-
PersistenceService.getInstance().setFirstTimePerformanceMetrics()
88+
if (PersistenceService.getInstance().isFirstTimePerformanceMetrics()) {
89+
PersistenceService.getInstance().setFirstTimePerformanceMetricsDone()
9090
}
9191
}
9292
}

src/main/kotlin/org/digma/intellij/plugin/ui/assets/AssetsService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class AssetsService(private val project: Project) : Disposable {
7878

7979
private fun checkInsightExists() {
8080

81-
if (!PersistenceService.getInstance().isFirstTimeAssetsReceived()) {
81+
if (!PersistenceService.getInstance().isFirstAssetsReceived()) {
8282
try {
8383
val insightsExists = AnalyticsService.getInstance(project).insightsExist
8484
val payload = objectMapper.readTree(insightsExists)
8585
if (!payload.isMissingNode && payload["insightExists"].asBoolean()) {
8686
ActivityMonitor.getInstance(project).registerFirstAssetsReceived()
87-
PersistenceService.getInstance().setFirstTimeAssetsReceived()
87+
PersistenceService.getInstance().setFirstAssetsReceived()
8888
}
8989
} catch (e: Throwable) {
9090
Log.warnWithException(logger, project, e, "error reporting FirstTimeAssetsReceived {}", e)

src/main/kotlin/org/digma/intellij/plugin/ui/insights/InsightsService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class InsightsService(val project: Project) : InsightsServiceImpl(project) {
176176

177177
private fun onInsightReceived(insights: String) {
178178

179-
if (PersistenceService.getInstance().isFirstTimeInsightReceived()) {
179+
if (PersistenceService.getInstance().isFirstInsightReceived()) {
180180
return
181181
}
182182

@@ -185,7 +185,7 @@ class InsightsService(val project: Project) : InsightsServiceImpl(project) {
185185
val totalCount = jsonNode.get("totalCount")
186186
if (totalCount.isInt && totalCount.asInt() > 0) {
187187
ActivityMonitor.getInstance(project).registerFirstInsightReceived()
188-
PersistenceService.getInstance().setFirstTimeInsightReceived()
188+
PersistenceService.getInstance().setFirstInsightReceived()
189189
}
190190
} catch (e: Throwable) {
191191
ErrorReporter.getInstance().reportError(project, "InsightsService.onInsightReceived", e)

src/main/kotlin/org/digma/intellij/plugin/ui/notificationcenter/IdleUserNotifications.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ fun startIdleUserTimers(parentDisposable: Disposable) {
3636
try {
3737

3838
//only show one message at a time
39-
if (PersistenceService.getInstance().isFirstTimeAssetsReceived() &&
39+
if (PersistenceService.getInstance().isFirstAssetsReceived() &&
4040
backendIdleDays() > 3 &&
4141
backendHasntBeenRunningLastNotified() > 7
4242
) {
4343
service<NotificationsPersistenceState>().state.backendHasntBeenRunningForAWhileLastNotified = Instant.now()
4444
showDigmaHasntBeenRunningForAWhile()
45-
} else if (PersistenceService.getInstance().isFirstTimeAssetsReceived() &&
45+
} else if (PersistenceService.getInstance().isFirstAssetsReceived() &&
4646
backendIdleDays() <= 1 &&
4747
userActionIdleDays() > 3 &&
4848
hasntBeenOpenedForAWhileLastNotified() > 7
4949
) {
5050
service<NotificationsPersistenceState>().state.hasntBeenOpenedForAWhileLastNotified = Instant.now()
5151
showDigmaHasntBeenOpenedForAWhile()
5252
} else if (PersistenceService.getInstance().isFirstTimeConnectionEstablished() &&
53-
!PersistenceService.getInstance().isFirstTimeAssetsReceived() &&
53+
!PersistenceService.getInstance().isFirstAssetsReceived() &&
5454
pluginInstalledDays() > 7 &&
5555
hasntBeenActivatedLastNotified() > 7
5656
) {

0 commit comments

Comments
 (0)