[core] Optmize caching (#1231)

This commit is contained in:
LoveSy 2021-10-07 00:03:46 +08:00 committed by GitHub
parent e2651eb4b2
commit 4a1fb57d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -451,6 +451,7 @@ public class ConfigManager {
final var obsoletePackages = new HashSet<Application>(); final var obsoletePackages = new HashSet<Application>();
final var obsoleteModules = new HashSet<Application>(); final var obsoleteModules = new HashSet<Application>();
final var moduleAvailability = new HashMap<Pair<String, Integer>, Boolean>(); final var moduleAvailability = new HashMap<Pair<String, Integer>, Boolean>();
final var cachedProcessScope = new HashMap<Pair<String, Integer>, List<ProcessScope>>();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Application app = new Application(); Application app = new Application();
app.packageName = cursor.getString(appPkgNameIdx); app.packageName = cursor.getString(appPkgNameIdx);
@ -478,7 +479,13 @@ public class ConfigManager {
if (app.packageName.equals("android")) continue; if (app.packageName.equals("android")) continue;
try { try {
List<ProcessScope> processesScope = getAssociatedProcesses(app); List<ProcessScope> processesScope = cachedProcessScope.computeIfAbsent(new Pair<>(app.packageName, app.userId), (k) -> {
try {
return getAssociatedProcesses(app);
} catch (RemoteException e) {
return Collections.emptyList();
}
});
if (processesScope.isEmpty()) { if (processesScope.isEmpty()) {
obsoletePackages.add(app); obsoletePackages.add(app);
continue; continue;