-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from 1c-syntax/feature/optimize
Оптимизация хранения и выполнения
- Loading branch information
Showing
216 changed files
with
20,219 additions
and
18,728 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
/* | ||
* This file is a part of MDClasses. | ||
* | ||
* Copyright (c) 2019 - 2024 | ||
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* MDClasses is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* MDClasses is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with MDClasses. | ||
*/ | ||
package com.github._1c_syntax.bsl.mdclasses; | ||
|
||
import com.github._1c_syntax.bsl.mdo.CommonModule; | ||
/* | ||
* This file is a part of MDClasses. | ||
* | ||
* Copyright (c) 2019 - 2024 | ||
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* MDClasses is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* MDClasses is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with MDClasses. | ||
*/ | ||
package com.github._1c_syntax.bsl.mdclasses; | ||
|
||
import com.github._1c_syntax.bsl.mdo.MD; | ||
import com.github._1c_syntax.bsl.mdo.Module; | ||
import com.github._1c_syntax.bsl.mdo.ModuleOwner; | ||
import com.github._1c_syntax.bsl.mdo.Subsystem; | ||
import com.github._1c_syntax.bsl.mdo.children.ObjectModule; | ||
import com.github._1c_syntax.bsl.mdo.support.ApplicationRunMode; | ||
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant; | ||
import com.github._1c_syntax.bsl.mdo.support.UsePurposes; | ||
|
@@ -38,7 +36,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.Optional; | ||
|
||
public interface CF extends MDClass, ConfigurationTree { | ||
|
||
|
@@ -85,24 +83,12 @@ public interface CF extends MDClass, ConfigurationTree { | |
/** | ||
* Возвращает соответствие пути к модулю его типу | ||
*/ | ||
default Map<URI, ModuleType> getModulesByType() { | ||
return getAllModules().stream().collect(Collectors.toMap(Module::getUri, Module::getModuleType)); | ||
} | ||
Map<URI, ModuleType> getModulesByType(); | ||
|
||
/** | ||
* Возвращает соответствие типов модулей их путям к файлам сгруппированные по представлению ссылки объекта-владельца | ||
* Возвращает соответствие пути к модулю к нему самому | ||
*/ | ||
default Map<String, Map<ModuleType, URI>> modulesByMDORef() { | ||
return getPlainChildren().stream() | ||
.filter(ModuleOwner.class::isInstance) | ||
.map(ModuleOwner.class::cast) | ||
.collect(Collectors.toMap( | ||
(MD md) -> md.getMdoReference().getMdoRef(), | ||
md -> md.getModules().stream() | ||
.collect(Collectors.toMap(Module::getModuleType, Module::getUri)) | ||
) | ||
); | ||
} | ||
Map<URI, Module> getModulesByURI(); | ||
|
||
/** | ||
* Возвращает соответствие типов модулей их путям к файлам для дочернего объекта | ||
|
@@ -126,15 +112,7 @@ default Map<ModuleType, URI> mdoModuleTypes(String mdoRef) { | |
/** | ||
* Возвращает соответствие пути файла модуля ссылке его владельца | ||
*/ | ||
default Map<URI, MdoReference> modulesByObject() { | ||
return getAllModules().stream().collect(Collectors.toMap(Module::getUri, (Module module) -> { | ||
if (module instanceof ObjectModule objectModule) { | ||
return objectModule.getOwner(); | ||
} else { | ||
return ((CommonModule) module).getMdoReference(); | ||
} | ||
})); | ||
} | ||
Map<URI, MD> getModulesByObject(); | ||
|
||
/** | ||
* Возвращает список подсистем, в состав которых входит объект метаданных | ||
|
@@ -165,4 +143,19 @@ default List<Subsystem> includedSubsystems(MdoReference mdoReference, boolean ad | |
.flatMap(subsystem -> subsystem.included(mdoReference, addParentSubsystem).stream()) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
default ModuleType getModuleTypeByURI(URI uri) { | ||
return getModulesByType().getOrDefault(uri, ModuleType.UNKNOWN); | ||
} | ||
|
||
@Override | ||
default Optional<Module> getModuleByUri(URI uri) { | ||
return Optional.ofNullable(getModulesByURI().get(uri)); | ||
} | ||
|
||
@Override | ||
default Optional<MD> findChild(URI uri) { | ||
return Optional.ofNullable(getModulesByObject().get(uri)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
/* | ||
* This file is a part of MDClasses. | ||
* | ||
* Copyright (c) 2019 - 2024 | ||
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* MDClasses is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* MDClasses is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with MDClasses. | ||
*/ | ||
package com.github._1c_syntax.bsl.mdclasses; | ||
/* | ||
* This file is a part of MDClasses. | ||
* | ||
* Copyright (c) 2019 - 2024 | ||
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* MDClasses is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* MDClasses is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with MDClasses. | ||
*/ | ||
package com.github._1c_syntax.bsl.mdclasses; | ||
|
||
import com.github._1c_syntax.bsl.mdo.AccountingRegister; | ||
import com.github._1c_syntax.bsl.mdo.AccumulationRegister; | ||
|
@@ -77,10 +77,13 @@ | |
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant; | ||
import com.github._1c_syntax.bsl.mdo.support.UseMode; | ||
import com.github._1c_syntax.bsl.mdo.support.UsePurposes; | ||
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader; | ||
import com.github._1c_syntax.bsl.support.CompatibilityMode; | ||
import com.github._1c_syntax.bsl.support.SupportVariant; | ||
import com.github._1c_syntax.bsl.types.ConfigurationSource; | ||
import com.github._1c_syntax.bsl.types.MdoReference; | ||
import com.github._1c_syntax.bsl.types.ModuleType; | ||
import com.github._1c_syntax.utils.Lazy; | ||
import lombok.Builder; | ||
import lombok.Builder.Default; | ||
import lombok.EqualsAndHashCode; | ||
|
@@ -89,8 +92,10 @@ | |
import lombok.ToString; | ||
import lombok.Value; | ||
|
||
import java.net.URI; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Корневой класс конфигурации 1с | ||
|
@@ -139,6 +144,7 @@ public class Configuration implements CF { | |
ApplicationRunMode defaultRunMode = ApplicationRunMode.AUTO; | ||
@Default | ||
List<Module> modules = Collections.emptyList(); | ||
Lazy<List<Module>> allModules = new Lazy<>(this::computeAllModules); | ||
@Default | ||
String vendor = ""; | ||
@Default | ||
|
@@ -243,6 +249,11 @@ public class Configuration implements CF { | |
|
||
@Singular | ||
List<MD> children; | ||
Lazy<List<MD>> plainChildren = new Lazy<>(this::computePlainChildren); | ||
|
||
Lazy<Map<URI, ModuleType>> modulesByType = new Lazy<>(this::computeModulesByType); | ||
Lazy<Map<URI, Module>> modulesByURI = new Lazy<>(this::computeModulesByURI); | ||
Lazy<Map<URI, MD>> modulesByObject = new Lazy<>(this::computeModulesByObject); | ||
|
||
/* | ||
* Свое | ||
|
@@ -306,6 +317,51 @@ public class Configuration implements CF { | |
@Default | ||
MultiLanguageString briefInformation = MultiLanguageString.EMPTY; | ||
|
||
@Override | ||
public List<Module> getAllModules() { | ||
return allModules.getOrCompute(); | ||
} | ||
|
||
@Override | ||
public List<MD> getPlainChildren() { | ||
return plainChildren.getOrCompute(); | ||
} | ||
|
||
@Override | ||
public Map<URI, ModuleType> getModulesByType() { | ||
return modulesByType.getOrCompute(); | ||
} | ||
|
||
@Override | ||
public Map<URI, MD> getModulesByObject() { | ||
return modulesByObject.getOrCompute(); | ||
} | ||
|
||
@Override | ||
public Map<URI, Module> getModulesByURI() { | ||
return modulesByURI.getOrCompute(); | ||
} | ||
|
||
private List<MD> computePlainChildren() { | ||
return LazyLoader.computePlainChildren(this); | ||
} | ||
|
||
private Map<URI, ModuleType> computeModulesByType() { | ||
return LazyLoader.computeModulesByType(this); | ||
} | ||
|
||
private Map<URI, MD> computeModulesByObject() { | ||
return LazyLoader.computeModulesByObject(this); | ||
} | ||
|
||
private List<Module> computeAllModules() { | ||
return LazyLoader.computeAllModules(this); | ||
} | ||
|
||
private Map<URI, Module> computeModulesByURI() { | ||
return LazyLoader.computeModulesByURI(this); | ||
} | ||
|
||
private static Configuration createEmptyConfiguration() { | ||
var emptyString = "empty"; | ||
|
||
|
Oops, something went wrong.