Skip to content

Commit 11d6203

Browse files
committed
reduce access of read thread in webDeployment jobs #694
1 parent 0464e23 commit 11d6203

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/fr/adrienbrault/idea/symfony2plugin/webDeployment/WebDeploymentProjectComponent.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.intellij.openapi.application.ApplicationManager;
55
import com.intellij.openapi.components.ProjectComponent;
66
import com.intellij.openapi.extensions.PluginId;
7+
import com.intellij.openapi.progress.ProgressIndicator;
8+
import com.intellij.openapi.progress.Task;
79
import com.intellij.openapi.project.DumbService;
810
import com.intellij.openapi.project.Project;
911
import fr.adrienbrault.idea.symfony2plugin.Settings;
@@ -44,10 +46,12 @@ public void projectOpened() {
4446

4547
// remote file downloader
4648
if(Settings.getInstance(project).remoteDevFileScheduler) {
49+
Symfony2ProjectComponent.getLogger().info("Starting Symfony webDeployment background scheduler");
50+
4751
DumbService.getInstance(project).smartInvokeLater(new Runnable() {
4852
@Override
4953
public void run() {
50-
new Timer().schedule(new MyTimerTask(), 10000, 300000);
54+
new Timer().schedule(new MyTimerTask(), 1000, 300000);
5155
}
5256
});
5357
}
@@ -63,19 +67,22 @@ private class MyTimerTask extends TimerTask {
6367

6468
@Override
6569
public void run() {
70+
if(!RemoteWebServerUtil.hasConfiguredRemoteFile(project)) {
71+
return;
72+
}
6673

6774
DumbService.getInstance(project).smartInvokeLater(new Runnable() {
6875
@Override
6976
public void run() {
70-
ApplicationManager.getApplication().runReadAction(new Runnable() {
77+
new Task.Backgroundable(project, "Symfony: Remote File Download", false) {
7178
@Override
72-
public void run() {
79+
public void run(@NotNull ProgressIndicator indicator) {
80+
Symfony2ProjectComponent.getLogger().info("Running background webDeployment dev download");
7381
RemoteWebServerUtil.collectRemoteFiles(project);
7482
}
75-
});
83+
}.queue();
7684
}
7785
});
78-
7986
}
8087
}
8188
}

src/fr/adrienbrault/idea/symfony2plugin/webDeployment/actions/SymfonyWebDeploymentDownloadAction.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.jetbrains.plugins.webDeployment.config.PublishConfig;
1212
import com.jetbrains.plugins.webDeployment.config.WebServerConfig;
1313
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
14+
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1415
import fr.adrienbrault.idea.symfony2plugin.webDeployment.utils.RemoteWebServerUtil;
1516
import org.jetbrains.annotations.NotNull;
1617

@@ -50,11 +51,8 @@ public void actionPerformed(AnActionEvent e) {
5051
new Task.Backgroundable(project, "Symfony: Downloading Files", false) {
5152
@Override
5253
public void run(@NotNull ProgressIndicator indicator) {
53-
ApplicationManager.getApplication().runReadAction(new Runnable() {
54-
public void run() {
55-
RemoteWebServerUtil.collectRemoteFiles(project);
56-
}
57-
});
54+
Symfony2ProjectComponent.getLogger().info("Running webDeployment dev download");
55+
RemoteWebServerUtil.collectRemoteFiles(project);
5856
}
5957
}.queue();
6058
}

src/fr/adrienbrault/idea/symfony2plugin/webDeployment/utils/RemoteWebServerUtil.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.adrienbrault.idea.symfony2plugin.webDeployment.utils;
22

3+
import com.intellij.openapi.application.ApplicationManager;
34
import com.intellij.openapi.project.Project;
45
import com.intellij.openapi.util.Condition;
56
import com.intellij.util.Function;
@@ -59,7 +60,7 @@ public static <T> T getExtensionInstance(@Nullable Project project, @NotNull Cla
5960
return null;
6061
}
6162

62-
public static void collectRemoteFiles(@NotNull Project project) {
63+
public static void collectRemoteFiles(final @NotNull Project project) {
6364
WebServerConfig defaultServer = PublishConfig.getInstance(project).findDefaultServer();
6465
if(defaultServer == null) {
6566
return;
@@ -72,8 +73,8 @@ public static void collectRemoteFiles(@NotNull Project project) {
7273
return;
7374
}
7475

75-
for (RemoteFileStorageInterface fileStorage : RemoteWebServerUtil.getExtension(project)) {
76-
Collection<FileObject> contents = new ArrayList<FileObject>();
76+
for (final RemoteFileStorageInterface fileStorage : RemoteWebServerUtil.getExtension(project)) {
77+
final Collection<FileObject> contents = new ArrayList<FileObject>();
7778

7879
for (Object s : fileStorage.files(project)) {
7980

@@ -88,7 +89,12 @@ public static void collectRemoteFiles(@NotNull Project project) {
8889
}
8990

9091
fileStorage.clear();
91-
fileStorage.build(project, contents);
92+
93+
ApplicationManager.getApplication().runReadAction(new Runnable() {
94+
public void run() {
95+
fileStorage.build(project, contents);
96+
}
97+
});
9298
}
9399

94100
connection.clone();

0 commit comments

Comments
 (0)