From e22f138e1cda235c766b367a70a2074f0e962b74 Mon Sep 17 00:00:00 2001 From: Ivan Chirkov Date: Mon, 3 Jul 2017 16:31:16 +0200 Subject: [PATCH] Statistics: added projectOpened persisting (IDEA-CR-22562) Removed code for persisting statistics on close. Added statistics persisting with delay on project opening. --- ...plicationStatisticsPersistenceComponent.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java index 7be49a9ac64c..bb97dfef49dd 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java @@ -16,7 +16,6 @@ package com.intellij.internal.statistic.persistence; import com.intellij.concurrency.JobScheduler; -import com.intellij.ide.AppLifecycleListener; import com.intellij.internal.statistic.UsagesCollector; import com.intellij.internal.statistic.beans.GroupDescriptor; import com.intellij.internal.statistic.beans.UsageDescriptor; @@ -44,7 +43,8 @@ import java.util.concurrent.TimeUnit; public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence implements PersistentStateComponent, BaseComponent { - private boolean persistOnClosing = false; + // 30 minutes considered enough for project indexing and other tasks + private static final int DELAY_IN_MIN = 30; private static final String TOKENIZER = ","; @@ -161,20 +161,11 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis @Override public void initComponent() { MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); - connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { - @Override - public void appClosing() { - persistOpenedProjects(); - persistOnClosing = false; - } - }); connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override - public void projectClosing(Project project) { - if (persistOnClosing && project != null) { - UsagesCollector.doPersistProjectUsages(project); - } + public void projectOpened(Project project) { + JobScheduler.getScheduler().schedule(() -> UsagesCollector.doPersistProjectUsages(project), DELAY_IN_MIN, TimeUnit.MINUTES); } });