Skip to content

Commit 3971111

Browse files
author
jantje
committed
performance improvements
instead of looking for all installable libraries I only look for the once I need.
1 parent 5309e5a commit 3971111

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,16 @@ public static Map<String, io.sloeber.core.managers.Library> getAllInstallableLib
366366
return ret;
367367
}
368368

369+
public static Map<String, io.sloeber.core.managers.Library> getLatestInstallableLibraries(
370+
Set<String> libnames) {
371+
Set<String> remainingLibNames=new TreeSet<>(libnames);
372+
Map<String, Library> ret = new HashMap<>();
373+
for (LibraryIndex libraryIndex : libraryIndices) {
374+
ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
375+
remainingLibNames.removeAll(ret.keySet());
376+
}
377+
378+
return ret;
379+
}
380+
369381
}

io.sloeber.core/src/io/sloeber/core/managers/Library.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.eclipse.core.runtime.Status;
1818

1919
import io.sloeber.core.Activator;
20+
import io.sloeber.core.common.Common;
2021
import io.sloeber.core.common.ConfigurationPreferences;
2122
import io.sloeber.core.tools.FileModifiers;
2223

@@ -159,6 +160,26 @@ public boolean isInstalled() {
159160
return getInstallPath().toFile().exists();
160161
}
161162

163+
/**
164+
* checks if any version of this library is installed. Can popup a window if
165+
* there is something wrong with the folder structure
166+
*
167+
* @return false if any version is installed. true in case of error and in case
168+
* no version is installed
169+
*/
170+
public boolean isAVersionInstalled() {
171+
if (!getInstallPath().getParent().toFile().exists()) {
172+
return false;
173+
}
174+
if (getInstallPath().getParent().toFile().isFile()) {
175+
// something is wrong here
176+
Common.log(new Status(IStatus.ERROR, Activator.getId(),
177+
getInstallPath().getParent() + " is a file but it should be a directory.")); //$NON-NLS-1$
178+
return false;
179+
}
180+
return getInstallPath().getParent().toFile().list().length > 0;
181+
}
182+
162183
public IStatus install(IProgressMonitor monitor) {
163184
monitor.setTaskName("Downloading and installing " + getName() + " library."); //$NON-NLS-1$ //$NON-NLS-2$
164185
if (isInstalled()) {
@@ -215,9 +236,9 @@ public int compareTo(Library other) {
215236
}
216237

217238
/**
218-
* delete the library This will delete all installed versions of the
219-
* library. Normally only 1 version can be installed so deleting all
220-
* versions should be delete 1 version
239+
* delete the library This will delete all installed versions of the library.
240+
* Normally only 1 version can be installed so deleting all versions should be
241+
* delete 1 version
221242
*
222243
* @param monitor
223244
* @return Status.OK_STATUS if delete is successful otherwise IStatus.ERROR

io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,23 @@ public Map<String, Library> getLatestLibraries() {
9494
return this.latestLibs;
9595
}
9696

97+
/**
98+
* get all the latest versions of alll libraries that can be installed but are
99+
* not yet installed To do so I find all latest libraries and I remove the once
100+
* that are installed.
101+
*
102+
* @return
103+
*/
97104
public Map<String, Library> getLatestInstallableLibraries() {
98105
Map<String, Library> ret = new HashMap<>();
99106
for (Entry<String, Library> curLibrary : this.latestLibs.entrySet()) {
100-
if (getInstalledLibrary(curLibrary.getKey())==null) {
107+
if (!curLibrary.getValue().isAVersionInstalled()) {
101108
ret.put(curLibrary.getKey(), curLibrary.getValue());
102109
}
103110
}
104111
return ret;
105112
}
113+
106114
public Collection<Library> getLibraries(String category) {
107115
Set<String> categoryLibs = this.categories.get(category);
108116
if (categoryLibs == null) {
@@ -131,4 +139,26 @@ public void setJsonFile(File packageFile) {
131139
public String getName() {
132140
return this.jsonFileName;
133141
}
142+
143+
/**
144+
* get all the latest versions of alll the libraries provided that can be
145+
* installed but are not yet installed To do so I find all latest libraries and
146+
* I remove the once that are installed.
147+
*
148+
* @return
149+
*/
150+
public Map<String, Library> getLatestInstallableLibraries(Set<String> libNames) {
151+
Map<String, Library> ret = new HashMap<>();
152+
if (libNames.isEmpty()) {
153+
return ret;
154+
}
155+
for (Entry<String, Library> curLibrary : this.latestLibs.entrySet()) {
156+
if (libNames.contains(curLibrary.getKey())) {
157+
if (!curLibrary.getValue().isAVersionInstalled()) {
158+
ret.put(curLibrary.getKey(), curLibrary.getValue());
159+
}
160+
}
161+
}
162+
return ret;
163+
}
134164
}

io.sloeber.core/src/io/sloeber/core/tools/Libraries.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ public static void checkLibraries(IProject affectedProject) {
401401
uninstalledIncludedHeaders.removeAll(installedLibs.keySet());
402402
if(!uninstalledIncludedHeaders.isEmpty()) {
403403
//some libraries may need to be installed
404-
Map<String, Library> availableLibs = LibraryManager.getAllInstallableLibraries();
405-
availableLibs.keySet().retainAll(uninstalledIncludedHeaders);
404+
405+
Map<String, Library> availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
406+
406407
if(!availableLibs.isEmpty()) {
407408
//We now know which libraries to install
408409
//TODO for now I just install but there should be some user
@@ -421,7 +422,13 @@ public static void checkLibraries(IProject affectedProject) {
421422
+ affectedProject.getName() + ": " + installedLibs.keySet().toString())); //$NON-NLS-1$
422423
addLibrariesToProject(affectedProject, configurationDescription, installedLibs);
423424
try {
425+
//TODO remove this logging code if this code is not causing the disrupts
426+
long startTime = System.nanoTime();
424427
mngr.setProjectDescription(affectedProject, projectDescription, true, null);
428+
long duration = (System.nanoTime() - startTime)/ 1000000; //in miliseconds
429+
if (duration>45000) {
430+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,"setProjectDescription took "+duration+" miliseconds!!!")); //$NON-NLS-1$ //$NON-NLS-2$
431+
}
425432
} catch (CoreException e) {
426433
// this can fail because the project may already
427434
// be

0 commit comments

Comments
 (0)