подправил кеширование отображаемых данных ( чтобы не распаковывать каждый раз список имен групп и прочее)

This commit is contained in:
2024-09-18 13:37:11 +03:00
parent f55a3a6324
commit 0cef474233
18 changed files with 181 additions and 85 deletions

View File

@@ -17,8 +17,8 @@ import java.util.Vector;
import java.util.stream.Collectors;
public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
//-
public static LinkedHashMap<Class, Object> selections = new LinkedHashMap<>();
//-
public LinkedHashMap<Class, Object> selections = new LinkedHashMap<>();
//---
public String Name;
public Class<K> k; //класс первичного ключа.
public Class<D> d; //класс объектов.

View File

@@ -0,0 +1,57 @@
package Common.UI.VisualCache;
import Common.Global;
import Common.Utils.Utils;
import TestingSystem.Common.Configuration.Configuration;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Group.Json.GroupJson;
import TestingSystem.Common.Group.Json.GroupsJson;
import TestingSystem.Common.Test.Json.TestJson;
import TestingSystem.Common.Test.Json.TestsJson;
import TestingSystem.Common.Test.Test;
import java.util.Vector;
public class ConfigurationCache extends VisualCache{
public GroupsJson groupsJson = null;
public Vector<String> groupsDescriptions = null;
public TestsJson testsJson = null;
//--
public ConfigurationCache(Configuration configuration) {
if (configuration.packedGroupsJson.isEmpty())
groupsJson = new GroupsJson(); //просто пустой
else
groupsJson = Utils.gson.fromJson(configuration.packedGroupsJson, GroupsJson.class);
//--
if (testsJson == null) {
if (configuration.packedTestsJson.isEmpty())
testsJson = new TestsJson(); //просто пустой
else
testsJson = Utils.gson.fromJson(configuration.packedTestsJson, TestsJson.class);
}
//-
groupsDescriptions = new Vector<>();
for (GroupJson groupJson : groupsJson.array)
groupsDescriptions.add(groupJson.description);
}
public int getTestsCount() {
return testsJson.array.size();
}
public Vector<String> getGroupsDescriptions() {
return groupsDescriptions;
}
public Vector<Group> getGroups(){
Vector<Group> groups = new Vector<>();
for (GroupJson groupJson : groupsJson.array){
if (Global.testingServer.db.groups.containsKey(groupJson.id))
groups.add(Global.testingServer.db.groups.get(groupJson.id));
}
return groups;
}
public Vector<Test> getTests(){
Vector<Test> tests = new Vector<>();
for (TestJson testJson : testsJson.array){
if (Global.testingServer.db.tests.containsKey(testJson.id))
tests.add(Global.testingServer.db.tests.get(testJson.id));
}
return tests;
}
}

View File

@@ -0,0 +1,3 @@
package Common.UI.VisualCache;
public class VisualCache {
}

View File

@@ -0,0 +1,46 @@
package Common.UI.VisualCache;
import Common.Database.DBObject;
import TestingSystem.Common.Configuration.Configuration;
import java.util.LinkedHashMap;
public class VisualCaches {
static LinkedHashMap<Class, LinkedHashMap<Object, VisualCache>> allData = new LinkedHashMap<>();
static LinkedHashMap<Object, VisualCache> getDataForClass(Class class_) {
LinkedHashMap<Object, VisualCache> data;
if (allData.containsKey(class_)) {
data = allData.get(class_);
} else {
data = new LinkedHashMap<>();
allData.put(class_, data);
}
return data;
}
//чтобы не трогать сами объекты и не сбить сериализацию
static VisualCache createCache(Object object) {
if (object instanceof Configuration)
return new ConfigurationCache((Configuration) object);
return new VisualCache();
}
public static VisualCache GetCache(DBObject object) {
// System.out.println("get visual cache for " + object.getPK());
VisualCache res = null;
LinkedHashMap<Object, VisualCache> data = getDataForClass(object.getClass());
if (!data.containsKey(object.getPK())) {
// System.out.println("cache not found, creating...");
data.put(object.getPK(), res = createCache(object));
} else {
// System.out.println("cache found");
res = data.get(object.getPK());
}
return res;
}
public static void DeleteCahce(DBObject object){
DeleteCahce(object.getClass(), object.getPK());
}
public static void DeleteCahce(Class class_, Object pk){
LinkedHashMap<Object, VisualCache> data = getDataForClass(class_);
if (data.containsKey(pk))
data.remove(pk);
}
}

View File

@@ -1,17 +1,13 @@
package TestingSystem.Common.Configuration;
import Common.Database.DBObject;
import Common.Database.riDBObject;
import Common.Global;
import Common.Utils.Utils;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Group.Json.GroupJson;
import TestingSystem.Common.Group.Json.GroupsJson;
import TestingSystem.Common.Test.Json.TestJson;
import TestingSystem.Common.Test.Json.TestsJson;
import TestingSystem.Common.Test.Test;
import com.sun.org.glassfish.gmbal.Description;
import java.util.LinkedHashMap;
import java.util.Vector;
public class Configuration extends riDBObject {
//конфигурация = данные для пакета.
@@ -34,14 +30,13 @@ public class Configuration extends riDBObject {
public String packedGroupsJson = "";
@Description("DEFAULT ''")
public String packedTestsJson = "";
//----
//---данные для отображения. кешировать их где-то еще? проблема что отправляются на сервер почем зря.
@Description("IGNORE")
public GroupsJson groupsJson = null;
@Description("IGNORE")
public Vector<String> groupsDescriptions = null;
@Description("IGNORE")
public TestsJson testsJson = null;
//--
public void saveGroupsAsJson(Vector<Group> groups) {
packedGroupsJson = Utils.jsonToPrettyFormat(Utils.gson.toJson(new GroupsJson(groups)));
}
public void saveTestsAsJson(Vector<Test> tests) {
packedTestsJson = Utils.jsonToPrettyFormat(Utils.gson.toJson(new TestsJson(tests)));
}
//--
@Override
public void SynchronizeFields(DBObject src) {
@@ -55,60 +50,4 @@ public class Configuration extends riDBObject {
packedTestsJson = c.packedTestsJson;
}
//-
public void saveGroupsAsJson(Vector<Group> groups) {
packedGroupsJson = Utils.jsonToPrettyFormat(Utils.gson.toJson(new GroupsJson(groups)));
}
void unpackGroupsAsJson() {
if (groupsJson == null) {
if (packedGroupsJson.isEmpty())
groupsJson = new GroupsJson(); //просто пустой
else
groupsJson = Utils.gson.fromJson(packedGroupsJson, GroupsJson.class);
}
}
public Vector<String> getGroupsDescriptions() {
if (groupsDescriptions==null) {
unpackGroupsAsJson();
groupsDescriptions = new Vector<>();
for (GroupJson groupJson : groupsJson.array)
groupsDescriptions.add(groupJson.description);
}
return groupsDescriptions;
}
public Vector<Group> getGroups() {
//здесь обращение реже так что буферизовать список групп не надо, тем более может меняться.
unpackGroupsAsJson();
Vector<Group> res = new Vector<>();
for (GroupJson groupJson: groupsJson.array){
if (Global.testingServer.db.groups.containsKey(groupJson.id))
res.add(Global.testingServer.db.groups.get(groupJson.id));
}
return res;
}
//--------------------------------------------------------------------->>>
public void saveTestsAsJson(Vector<Test> tests) {
packedTestsJson = Utils.jsonToPrettyFormat(Utils.gson.toJson(new TestsJson(tests)));
}
void unpackTestsAsJson() {
if (testsJson == null) {
if (packedTestsJson.isEmpty())
testsJson = new TestsJson(); //просто пустой
else
testsJson = Utils.gson.fromJson(packedTestsJson, TestsJson.class);
}
}
public int getTestsCount(){
unpackTestsAsJson();
return testsJson.array.size();
}
public Vector<Test> getTests() {
//здесь обращение реже так что буферизовать список групп не надо, тем более может меняться.
unpackTestsAsJson();
Vector<Test> res = new Vector<>();
for (TestJson testJson: testsJson.array){
if (Global.testingServer.db.tests.containsKey(testJson.id))
res.add(Global.testingServer.db.tests.get(testJson.id));
}
return res;
}
}

View File

@@ -2,8 +2,12 @@ package TestingSystem.DVM.DVMConfiguration;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.iDBTable;
import Common.Global;
import Common.UI.DataSetControlForm;
import Common.UI.Tables.TableRenderers;
import Common.UI.VisualCache.ConfigurationCache;
import Common.UI.VisualCache.VisualCache;
import Common.UI.VisualCache.VisualCaches;
import Common.UI.VisualiserStringList;
import Common.UI.Windows.Dialog.DBObjectDialog;
import Common.Utils.Utils;
@@ -62,23 +66,24 @@ public class DVMConfigurationDBTable extends iDBTable<DVMConfiguration> {
}
@Override
public Object getFieldAt(DVMConfiguration object, int columnIndex) {
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(object);
switch (columnIndex) {
case 2:
return object.description;
case 3:
return object.sender_name;
//---
case 4:
return object.printAuto();
case 5:
return object.getGroupsDescriptions();
return cache.getGroupsDescriptions();
case 6:
return object.getTestsCount();
//---
return cache.getTestsCount();
//todo упростить. и флаги и окружение будут просто одной строкой. мульти не актуально.
case 7:
return Utils.unpackStrings(object.flags, true);
case 8:
return Utils.unpackStrings(object.environments, true);
//------------------------------------------------------------------------------------
case 9:
return object.c_maxtime;
case 10:

View File

@@ -2,7 +2,7 @@ package Visual_DVM_2021.Passes.All;
import Common.Global;
import TestingSystem.Common.TestingServer;
import TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
import Visual_DVM_2021.Passes.DeleteServerObjects;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
public class DeleteConfiguration extends DeleteServerObjects<TestingServer, DVMConfiguration> {
public DeleteConfiguration() {
super(Global.testingServer, DVMConfiguration.class);

View File

@@ -2,7 +2,7 @@ package Visual_DVM_2021.Passes.All;
import Common.Global;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.DeleteServerObjects;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
public class DeleteGroup extends DeleteServerObjects<TestingServer, Group> {
public DeleteGroup() {
super(Global.testingServer, Group.class);

View File

@@ -2,7 +2,7 @@ package Visual_DVM_2021.Passes.All;
import Common.Global;
import TestingSystem.Common.TestingServer;
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import Visual_DVM_2021.Passes.DeleteServerObjects;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
public class DeleteSapforConfiguration extends DeleteServerObjects<TestingServer, SapforConfiguration> {
public DeleteSapforConfiguration() {
super(Global.testingServer, SapforConfiguration.class);

View File

@@ -2,7 +2,7 @@ package Visual_DVM_2021.Passes.All;
import Common.Global;
import TestingSystem.Common.TestingServer;
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommand;
import Visual_DVM_2021.Passes.DeleteServerObjects;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
public class DeleteSapforConfigurationCommand extends DeleteServerObjects<TestingServer, SapforConfigurationCommand> {
public DeleteSapforConfigurationCommand() {
super(Global.testingServer, SapforConfigurationCommand.class);

View File

@@ -2,7 +2,7 @@ package Visual_DVM_2021.Passes.All;
import Common.Global;
import TestingSystem.Common.Test.Test;
import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.DeleteServerObjects;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
public class DeleteTest extends DeleteServerObjects<TestingServer, Test> {
public DeleteTest() {
super(Global.testingServer, Test.class);

View File

@@ -1,6 +1,8 @@
package Visual_DVM_2021.Passes.All;
import Common.Current;
import Common.Global;
import Common.UI.VisualCache.ConfigurationCache;
import Common.UI.VisualCache.VisualCaches;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test;
import TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
@@ -32,8 +34,9 @@ public class ShowCurrentDVMConfigurationTests extends Pass_2021<DVMConfiguration
@Override
protected void showDone() throws Exception {
System.out.println("package="+target.id);
Vector<Group> groups = target.getGroups();
Vector<Test> tests = target.getTests();
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(target);
Vector<Group> groups = cache.getGroups();
Vector<Test> tests = cache.getTests();
//-----
//--
for (Group group: groups)

View File

@@ -2,6 +2,8 @@ package Visual_DVM_2021.Passes.All;
import Common.Current;
import Common.Global;
import Common.UI.UI;
import Common.UI.VisualCache.ConfigurationCache;
import Common.UI.VisualCache.VisualCaches;
import Common.Utils.Utils;
import GlobalData.Compiler.CompilerType;
import GlobalData.Machine.MachineType;
@@ -141,8 +143,9 @@ public class StartSelectedDVMConfigurations extends PublishServerObject<TestingS
);
//----
for (DVMConfiguration configuration: configurations) {
groups = configuration.getGroups();
tests = configuration.getTests();
ConfigurationCache cache = (ConfigurationCache) VisualCaches.GetCache(configuration);
groups = cache.getGroups();
tests = cache.getTests();
//-
for (Group group: groups){
Vector<Test> groupTests = new Vector<>();

View File

@@ -4,10 +4,11 @@ import Common.Global;
import Common.Utils.Utils;
import TestingSystem.Common.TestingPackage.TestingPackage;
import TestingSystem.Common.TestingServer;
import Visual_DVM_2021.Passes.Server.DeleteServerObjects;
import java.io.File;
import java.util.Vector;
public abstract class DeleteTestingPackages<P extends TestingPackage> extends DeleteServerObjects<TestingServer, P>{
public abstract class DeleteTestingPackages<P extends TestingPackage> extends DeleteServerObjects<TestingServer, P> {
boolean delete_draft;
public DeleteTestingPackages(Class<P> p) {
super(Global.testingServer, p);

View File

@@ -1,5 +1,7 @@
package Visual_DVM_2021.Passes.Server;
import Common.Database.DBObject;
import Common.UI.VisualCache.VisualCache;
import Common.UI.VisualCache.VisualCaches;
import Repository.RepositoryServer;
public class DeleteServerObject<S extends RepositoryServer, D extends DBObject> extends ServerObjectPass<S, D> {
@Override
@@ -11,6 +13,11 @@ public class DeleteServerObject<S extends RepositoryServer, D extends DBObject>
target = (D) getDb().tables.get(d).getCurrent();
return getDb().tables.get(d).CheckCurrent(Log) && getDb().tables.get(d).ShowDeleteObjectDialog(target);
}
@Override
protected void performPreparation() throws Exception {
super.performPreparation();
VisualCaches.DeleteCahce(target);
}
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.
@Override
protected void showPreparation() throws Exception {

View File

@@ -1,9 +1,10 @@
package Visual_DVM_2021.Passes;
package Visual_DVM_2021.Passes.Server;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.DBTable;
import Common.Database.Database;
import Common.UI.UI;
import Common.UI.VisualCache.VisualCaches;
import Repository.RepositoryServer;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
@@ -48,6 +49,13 @@ public class DeleteServerObjects <S extends RepositoryServer, D extends DBObject
return false;
}
}
@Override
protected void performPreparation() throws Exception {
super.performPreparation();
for (Object key: target){
VisualCaches.DeleteCahce(d, key);
}
}
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.
@Override
protected void showPreparation() throws Exception {

View File

@@ -1,5 +1,6 @@
package Visual_DVM_2021.Passes.Server;
import Common.Database.DBObject;
import Common.UI.VisualCache.VisualCaches;
import Repository.RepositoryServer;
public class EditServerObject<S extends RepositoryServer, D extends DBObject> extends ServerObjectPass<S, D> {
//--
@@ -13,6 +14,12 @@ public class EditServerObject<S extends RepositoryServer, D extends DBObject> ex
target = (D) getDb().tables.get(d).getCurrent();
return getDb().tables.get(d).CheckCurrent(Log) && getDb().tables.get(d).ShowEditObjectDialog(target);
}
@Override
protected void performPreparation() throws Exception {
super.performPreparation();
//очистить кэш.
VisualCaches.DeleteCahce(target);
}
//--
public EditServerObject(S server_in, Class<D> d_in) {
super(server_in, d_in);