Skip to content

Commit 177b0ea

Browse files
authored
Merge pull request #449 from 1c-syntax/feature/optimize
Оптимизация хранения и выполнения
2 parents bc8709a + e54a056 commit 177b0ea

File tree

216 files changed

+20219
-18728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+20219
-18728
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ dependencies {
5555

5656
// прочее
5757
implementation("commons-io", "commons-io", "2.8.0")
58-
implementation("com.github.1c-syntax", "utils", "0.5.1")
58+
implementation("io.github.1c-syntax", "utils", "0.6.0")
5959
implementation("io.github.1c-syntax", "bsl-common-library", "0.5.1")
60-
implementation("io.github.1c-syntax", "supportconf", "0.13.1") {
60+
implementation("io.github.1c-syntax", "supportconf", "0.14.0") {
6161
exclude("io.github.1c-syntax", "bsl-common-library")
6262
}
6363

src/main/java/com/github/_1c_syntax/bsl/mdclasses/CF.java

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
/*
2-
* This file is a part of MDClasses.
3-
*
4-
* Copyright (c) 2019 - 2024
5-
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6-
*
7-
* SPDX-License-Identifier: LGPL-3.0-or-later
8-
*
9-
* MDClasses is free software; you can redistribute it and/or
10-
* modify it under the terms of the GNU Lesser General Public
11-
* License as published by the Free Software Foundation; either
12-
* version 3.0 of the License, or (at your option) any later version.
13-
*
14-
* MDClasses is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17-
* Lesser General Public License for more details.
18-
*
19-
* You should have received a copy of the GNU Lesser General Public
20-
* License along with MDClasses.
21-
*/
22-
package com.github._1c_syntax.bsl.mdclasses;
23-
24-
import com.github._1c_syntax.bsl.mdo.CommonModule;
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2024
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdclasses;
23+
2524
import com.github._1c_syntax.bsl.mdo.MD;
2625
import com.github._1c_syntax.bsl.mdo.Module;
2726
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
2827
import com.github._1c_syntax.bsl.mdo.Subsystem;
29-
import com.github._1c_syntax.bsl.mdo.children.ObjectModule;
3028
import com.github._1c_syntax.bsl.mdo.support.ApplicationRunMode;
3129
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
3230
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
@@ -38,7 +36,7 @@
3836
import java.util.Collections;
3937
import java.util.List;
4038
import java.util.Map;
41-
import java.util.stream.Collectors;
39+
import java.util.Optional;
4240

4341
public interface CF extends MDClass, ConfigurationTree {
4442

@@ -85,24 +83,12 @@ public interface CF extends MDClass, ConfigurationTree {
8583
/**
8684
* Возвращает соответствие пути к модулю его типу
8785
*/
88-
default Map<URI, ModuleType> getModulesByType() {
89-
return getAllModules().stream().collect(Collectors.toMap(Module::getUri, Module::getModuleType));
90-
}
86+
Map<URI, ModuleType> getModulesByType();
9187

9288
/**
93-
* Возвращает соответствие типов модулей их путям к файлам сгруппированные по представлению ссылки объекта-владельца
89+
* Возвращает соответствие пути к модулю к нему самому
9490
*/
95-
default Map<String, Map<ModuleType, URI>> modulesByMDORef() {
96-
return getPlainChildren().stream()
97-
.filter(ModuleOwner.class::isInstance)
98-
.map(ModuleOwner.class::cast)
99-
.collect(Collectors.toMap(
100-
(MD md) -> md.getMdoReference().getMdoRef(),
101-
md -> md.getModules().stream()
102-
.collect(Collectors.toMap(Module::getModuleType, Module::getUri))
103-
)
104-
);
105-
}
91+
Map<URI, Module> getModulesByURI();
10692

10793
/**
10894
* Возвращает соответствие типов модулей их путям к файлам для дочернего объекта
@@ -126,15 +112,7 @@ default Map<ModuleType, URI> mdoModuleTypes(String mdoRef) {
126112
/**
127113
* Возвращает соответствие пути файла модуля ссылке его владельца
128114
*/
129-
default Map<URI, MdoReference> modulesByObject() {
130-
return getAllModules().stream().collect(Collectors.toMap(Module::getUri, (Module module) -> {
131-
if (module instanceof ObjectModule objectModule) {
132-
return objectModule.getOwner();
133-
} else {
134-
return ((CommonModule) module).getMdoReference();
135-
}
136-
}));
137-
}
115+
Map<URI, MD> getModulesByObject();
138116

139117
/**
140118
* Возвращает список подсистем, в состав которых входит объект метаданных
@@ -165,4 +143,19 @@ default List<Subsystem> includedSubsystems(MdoReference mdoReference, boolean ad
165143
.flatMap(subsystem -> subsystem.included(mdoReference, addParentSubsystem).stream())
166144
.toList();
167145
}
146+
147+
@Override
148+
default ModuleType getModuleTypeByURI(URI uri) {
149+
return getModulesByType().getOrDefault(uri, ModuleType.UNKNOWN);
150+
}
151+
152+
@Override
153+
default Optional<Module> getModuleByUri(URI uri) {
154+
return Optional.ofNullable(getModulesByURI().get(uri));
155+
}
156+
157+
@Override
158+
default Optional<MD> findChild(URI uri) {
159+
return Optional.ofNullable(getModulesByObject().get(uri));
160+
}
168161
}

src/main/java/com/github/_1c_syntax/bsl/mdclasses/Configuration.java

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/*
2-
* This file is a part of MDClasses.
3-
*
4-
* Copyright (c) 2019 - 2024
5-
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6-
*
7-
* SPDX-License-Identifier: LGPL-3.0-or-later
8-
*
9-
* MDClasses is free software; you can redistribute it and/or
10-
* modify it under the terms of the GNU Lesser General Public
11-
* License as published by the Free Software Foundation; either
12-
* version 3.0 of the License, or (at your option) any later version.
13-
*
14-
* MDClasses is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17-
* Lesser General Public License for more details.
18-
*
19-
* You should have received a copy of the GNU Lesser General Public
20-
* License along with MDClasses.
21-
*/
22-
package com.github._1c_syntax.bsl.mdclasses;
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2024
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdclasses;
2323

2424
import com.github._1c_syntax.bsl.mdo.AccountingRegister;
2525
import com.github._1c_syntax.bsl.mdo.AccumulationRegister;
@@ -77,10 +77,13 @@
7777
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
7878
import com.github._1c_syntax.bsl.mdo.support.UseMode;
7979
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
80+
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader;
8081
import com.github._1c_syntax.bsl.support.CompatibilityMode;
8182
import com.github._1c_syntax.bsl.support.SupportVariant;
8283
import com.github._1c_syntax.bsl.types.ConfigurationSource;
8384
import com.github._1c_syntax.bsl.types.MdoReference;
85+
import com.github._1c_syntax.bsl.types.ModuleType;
86+
import com.github._1c_syntax.utils.Lazy;
8487
import lombok.Builder;
8588
import lombok.Builder.Default;
8689
import lombok.EqualsAndHashCode;
@@ -89,8 +92,10 @@
8992
import lombok.ToString;
9093
import lombok.Value;
9194

95+
import java.net.URI;
9296
import java.util.Collections;
9397
import java.util.List;
98+
import java.util.Map;
9499

95100
/**
96101
* Корневой класс конфигурации 1с
@@ -139,6 +144,7 @@ public class Configuration implements CF {
139144
ApplicationRunMode defaultRunMode = ApplicationRunMode.AUTO;
140145
@Default
141146
List<Module> modules = Collections.emptyList();
147+
Lazy<List<Module>> allModules = new Lazy<>(this::computeAllModules);
142148
@Default
143149
String vendor = "";
144150
@Default
@@ -243,6 +249,11 @@ public class Configuration implements CF {
243249

244250
@Singular
245251
List<MD> children;
252+
Lazy<List<MD>> plainChildren = new Lazy<>(this::computePlainChildren);
253+
254+
Lazy<Map<URI, ModuleType>> modulesByType = new Lazy<>(this::computeModulesByType);
255+
Lazy<Map<URI, Module>> modulesByURI = new Lazy<>(this::computeModulesByURI);
256+
Lazy<Map<URI, MD>> modulesByObject = new Lazy<>(this::computeModulesByObject);
246257

247258
/*
248259
* Свое
@@ -306,6 +317,51 @@ public class Configuration implements CF {
306317
@Default
307318
MultiLanguageString briefInformation = MultiLanguageString.EMPTY;
308319

320+
@Override
321+
public List<Module> getAllModules() {
322+
return allModules.getOrCompute();
323+
}
324+
325+
@Override
326+
public List<MD> getPlainChildren() {
327+
return plainChildren.getOrCompute();
328+
}
329+
330+
@Override
331+
public Map<URI, ModuleType> getModulesByType() {
332+
return modulesByType.getOrCompute();
333+
}
334+
335+
@Override
336+
public Map<URI, MD> getModulesByObject() {
337+
return modulesByObject.getOrCompute();
338+
}
339+
340+
@Override
341+
public Map<URI, Module> getModulesByURI() {
342+
return modulesByURI.getOrCompute();
343+
}
344+
345+
private List<MD> computePlainChildren() {
346+
return LazyLoader.computePlainChildren(this);
347+
}
348+
349+
private Map<URI, ModuleType> computeModulesByType() {
350+
return LazyLoader.computeModulesByType(this);
351+
}
352+
353+
private Map<URI, MD> computeModulesByObject() {
354+
return LazyLoader.computeModulesByObject(this);
355+
}
356+
357+
private List<Module> computeAllModules() {
358+
return LazyLoader.computeAllModules(this);
359+
}
360+
361+
private Map<URI, Module> computeModulesByURI() {
362+
return LazyLoader.computeModulesByURI(this);
363+
}
364+
309365
private static Configuration createEmptyConfiguration() {
310366
var emptyString = "empty";
311367

0 commit comments

Comments
 (0)