Skip to content

Оптимизации #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
// прочее
implementation("commons-io", "commons-io", "2.8.0")
implementation("io.github.1c-syntax", "utils", "0.6.1")
implementation("io.github.1c-syntax", "bsl-common-library", "0.6.0")
implementation("io.github.1c-syntax", "bsl-common-library", "0.7.0")
implementation("io.github.1c-syntax", "supportconf", "0.14.0") {
exclude("io.github.1c-syntax", "bsl-common-library")
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/github/_1c_syntax/bsl/mdclasses/CF.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.mdclasses;

import com.github._1c_syntax.bsl.mdo.CommonModule;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.Module;
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
Expand Down Expand Up @@ -90,6 +91,16 @@ public interface CF extends MDClass, ConfigurationTree, CFAccess {
*/
Map<URI, Module> getModulesByURI();

/**
* Возвращает соответствие имени общего модуля к нему самому
*/
Map<String, CommonModule> getCommonModulesByName();

/**
* Возвращает соответствие ссылки на дочерний объект к нему самому
*/
Map<MdoReference, MD> getChildrenByMdoRef();

/**
* Возвращает соответствие типов модулей их путям к файлам для дочернего объекта
*/
Expand Down Expand Up @@ -158,4 +169,14 @@ default Optional<Module> getModuleByUri(URI uri) {
default Optional<MD> findChild(URI uri) {
return Optional.ofNullable(getModulesByObject().get(uri));
}

@Override
default Optional<MD> findChild(MdoReference ref) {
return Optional.ofNullable(getChildrenByMdoRef().get(ref));
}

@Override
default Optional<CommonModule> findCommonModule(String name) {
return Optional.ofNullable(getCommonModulesByName().get(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ public class Configuration implements CF {
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);
Lazy<Map<String, CommonModule>> commonModulesByName = new Lazy<>(this::computeCommonModulesByName);
Lazy<Map<MdoReference, MD>> childrenByMdoRef = new Lazy<>(this::computeChildrenByMdoRef);

/*
* Свое
Expand Down Expand Up @@ -345,6 +347,16 @@ public Map<URI, Module> getModulesByURI() {
return modulesByURI.getOrCompute();
}

@Override
public Map<String, CommonModule> getCommonModulesByName() {
return commonModulesByName.getOrCompute();
}

@Override
public Map<MdoReference, MD> getChildrenByMdoRef() {
return childrenByMdoRef.getOrCompute();
}

/**
* Возвращает перечень возможных прав доступа
*/
Expand Down Expand Up @@ -372,6 +384,14 @@ private Map<URI, Module> computeModulesByURI() {
return LazyLoader.computeModulesByURI(this);
}

private Map<String, CommonModule> computeCommonModulesByName() {
return LazyLoader.computeCommonModulesByName(this);
}

private Map<MdoReference, MD> computeChildrenByMdoRef() {
return LazyLoader.computeChildrenByMdoRef(this);
}

private static Configuration createEmptyConfiguration() {
var emptyString = "empty";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public class ConfigurationExtension implements CF {
Lazy<Map<URI, ModuleType>> modulesByType = new Lazy<>(this::computeModulesByType);
Lazy<Map<URI, MD>> modulesByObject = new Lazy<>(this::computeModulesByObject);
Lazy<Map<URI, Module>> modulesByURI = new Lazy<>(this::computeModulesByURI);
Lazy<Map<String, CommonModule>> commonModulesByName = new Lazy<>(this::computeCommonModulesByName);
Lazy<Map<MdoReference, MD>> childrenByMdoRef = new Lazy<>(this::computeChildrenByMdoRef);

/*
* Свое
Expand Down Expand Up @@ -290,6 +292,16 @@ public Map<URI, Module> getModulesByURI() {
return modulesByURI.getOrCompute();
}

@Override
public Map<String, CommonModule> getCommonModulesByName() {
return commonModulesByName.getOrCompute();
}

@Override
public Map<MdoReference, MD> getChildrenByMdoRef() {
return childrenByMdoRef.getOrCompute();
}

/**
* Возвращает перечень возможных прав доступа
*/
Expand Down Expand Up @@ -317,4 +329,12 @@ private Map<URI, Module> computeModulesByURI() {
return LazyLoader.computeModulesByURI(this);
}

private Map<String, CommonModule> computeCommonModulesByName() {
return LazyLoader.computeCommonModulesByName(this);
}

private Map<MdoReference, MD> computeChildrenByMdoRef() {
return LazyLoader.computeChildrenByMdoRef(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static boolean rightAccess(CF cf, MdoReference mdoReference, RoleRight r
.filter(roleData -> !roleData.equals(RoleData.EMPTY))
.map(RoleData::getObjectRights)
.flatMap(Collection::stream)
.filter(objectRight -> objectRight.getName().equals(mdoReference.getMdoRef()))
.filter(objectRight -> objectRight.getName().equals(mdoReference))
.map(RoleData.ObjectRight::getRights)
.flatMap(Collection::stream)
.anyMatch(right -> roleRight == right.getName() && right.isValue());
Expand All @@ -155,11 +155,10 @@ private static List<Role> rolesAccess(CF cf, MdoReference mdoReference, RoleRigh
return Collections.emptyList();
}

var mdoRef = mdoReference.getMdoRef();
List<Role> roles = new ArrayList<>();
cf.getRoles().forEach((Role role) -> {
var hasAcccess = role.getData().getObjectRights().stream()
.filter(objectRight -> objectRight.getName().equals(mdoRef))
.filter(objectRight -> objectRight.getName().equals(mdoReference))
.map(RoleData.ObjectRight::getRights)
.flatMap(Collection::stream)
.anyMatch(right -> roleRight == right.getName() && right.isValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class CommonForm implements MDObject, Form, AccessRightsOwner {
FormType formType = FormType.MANAGED;

@Default
FormData data = EmptyFormData.getEmpty();
FormData data = EmptyFormData.EMPTY;

/*
* Свое
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ObjectForm implements Form, MDChild {
FormType formType = FormType.MANAGED;

@Default
FormData data = EmptyFormData.getEmpty();
FormData data = EmptyFormData.EMPTY;

/*
* Для MDChild
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,49 @@
*/
package com.github._1c_syntax.bsl.mdo.storage;

import com.github._1c_syntax.bsl.mdo.storage.form.FormAttribute;
import com.github._1c_syntax.bsl.mdo.storage.form.FormHandler;
import com.github._1c_syntax.bsl.mdo.storage.form.FormItem;
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;

import java.util.Collections;
import java.util.List;

/**
* Реализация содержимого пустой формы
*/
public class EmptyFormData implements FormData {

private static final EmptyFormData EMPTY = new EmptyFormData();
public final class EmptyFormData implements FormData {

/**
* Возвращает ссылку на пустое содержимое формы
*
* @return Пустое содержимое формы
*/
public static EmptyFormData getEmpty() {
return EMPTY;
public static final EmptyFormData EMPTY = new EmptyFormData();

private EmptyFormData() {
}

@Override
public MultiLanguageString getTitle() {
return MultiLanguageString.EMPTY;
}

@Override
public List<FormHandler> getHandlers() {
return Collections.emptyList();
}

@Override
public List<FormItem> getItems() {
return Collections.emptyList();
}

@Override
public List<FormItem> getPlainItems() {
return Collections.emptyList();
}

@Override
public boolean isEmpty() {
return true;
public List<FormAttribute> getAttributes() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
*/
package com.github._1c_syntax.bsl.mdo.storage;

import lombok.Value;

/**
* Реализация пустого содержимого макета
*/
@Value
public class EmptyTemplateData implements TemplateData {
public final class EmptyTemplateData implements TemplateData {
private static final EmptyTemplateData EMPTY = new EmptyTemplateData();

private EmptyTemplateData() {
}

/**
* Возвращает ссылку на пустое содержимое макета
*
Expand Down
72 changes: 30 additions & 42 deletions src/main/java/com/github/_1c_syntax/bsl/mdo/storage/FormData.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2024
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.mdo.storage;
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2024
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> 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.mdo.storage;

import com.github._1c_syntax.bsl.mdo.storage.form.FormAttribute;
import com.github._1c_syntax.bsl.mdo.storage.form.FormHandler;
import com.github._1c_syntax.bsl.mdo.storage.form.FormItem;
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -37,42 +35,32 @@ public interface FormData {
/**
* Признак пустого содержимого
*/
boolean isEmpty();
default boolean isEmpty() {
return this == EmptyFormData.EMPTY;
}

/**
* Заголовок формы
*/
default MultiLanguageString getTitle() {
return MultiLanguageString.EMPTY;
}
MultiLanguageString getTitle();

/**
* Обработчики событий формы
*/
default List<FormHandler> getHandlers() {
return Collections.emptyList();
}
List<FormHandler> getHandlers();

/**
* Список визуальных элементов формы первого уровня (т.е. с родителем - форма)
*/
default List<FormItem> getItems() {
return Collections.emptyList();
}
List<FormItem> getItems();

/**
* Список всех визуальных элементов формы
*/
default List<FormItem> getPlainItems() {
List<FormItem> allItems = new ArrayList<>(getItems());
getItems().forEach(formItem -> allItems.addAll(formItem.getPlainItems()));
return allItems;
}
List<FormItem> getPlainItems();

/**
* Список реквизитов формы
*/
default List<FormAttribute> getAttributes() {
return Collections.emptyList();
}
List<FormAttribute> getAttributes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.github._1c_syntax.bsl.mdo.storage.form.FormHandler;
import com.github._1c_syntax.bsl.mdo.storage.form.FormItem;
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader;
import com.github._1c_syntax.utils.Lazy;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Singular;
Expand All @@ -47,8 +49,14 @@ public class ManagedFormData implements FormData {
@Singular("addAttributes")
List<FormAttribute> attributes;

Lazy<List<FormItem>> plainItems = new Lazy<>(this::computePlainItems);

@Override
public boolean isEmpty() {
return false;
public List<FormItem> getPlainItems() {
return plainItems.getOrCompute();
}

private List<FormItem> computePlainItems() {
return LazyLoader.computePlainFormItems(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.github._1c_syntax.bsl.mdo.storage;

import com.github._1c_syntax.bsl.mdo.support.RoleRight;
import com.github._1c_syntax.bsl.types.MdoReference;
import com.github._1c_syntax.utils.GenericInterner;
import lombok.Builder;
import lombok.Builder.Default;
Expand Down Expand Up @@ -73,7 +74,7 @@ public static class ObjectRight {
* Имя субъекта права (mdoref и базовые)
*/
@Default
String name = "";
MdoReference name = MdoReference.EMPTY;

/**
* Набор самих прав
Expand Down
Loading
Loading