Statistics: added projectOpened persisting (IDEA-CR-22562)

Removed code for persisting statistics on close.
Added statistics persisting with delay on project opening.
This commit is contained in:
Ivan Chirkov
2017-07-03 16:33:12 +02:00
parent 8e18282c68
commit e22f138e1c
@@ -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<Element>,
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);
}
});