Skip to content

Commit

Permalink
Merge pull request #449 from 1c-syntax/feature/optimize
Browse files Browse the repository at this point in the history
Оптимизация хранения и выполнения
  • Loading branch information
theshadowco authored Mar 19, 2024
2 parents bc8709a + e54a056 commit 177b0ea
Show file tree
Hide file tree
Showing 216 changed files with 20,219 additions and 18,728 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ dependencies {

// прочее
implementation("commons-io", "commons-io", "2.8.0")
implementation("com.github.1c-syntax", "utils", "0.5.1")
implementation("io.github.1c-syntax", "utils", "0.6.0")
implementation("io.github.1c-syntax", "bsl-common-library", "0.5.1")
implementation("io.github.1c-syntax", "supportconf", "0.13.1") {
implementation("io.github.1c-syntax", "supportconf", "0.14.0") {
exclude("io.github.1c-syntax", "bsl-common-library")
}

Expand Down
93 changes: 43 additions & 50 deletions src/main/java/com/github/_1c_syntax/bsl/mdclasses/CF.java
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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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();

/**
* Возвращает соответствие типов модулей их путям к файлам для дочернего объекта
Expand All @@ -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();

/**
* Возвращает список подсистем, в состав которых входит объект метаданных
Expand Down Expand Up @@ -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));
}
}
100 changes: 78 additions & 22 deletions src/main/java/com/github/_1c_syntax/bsl/mdclasses/Configuration.java
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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с
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

/*
* Свое
Expand Down Expand Up @@ -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";

Expand Down
Loading

0 comments on commit 177b0ea

Please sign in to comment.