英文:
vaadin slow UI when loading MYSQL DB
问题
以下是您要翻译的内容:
我有一个 Vaadin 客户端应用程序,它使用内存中的数据库,并且我添加了切换到 MySQL 的可能性。我将后端用作 API。所有使用这些 MySQL 方法而不是内存数据库的操作在客户端上都需要很长时间(至少每个操作 30 秒),但在 MySQL 一侧仍然是即时的。
public SingletonGraph updateGraph (boolean isMySQL){
g = null;
if (isMySQL) {
fixGraphData(new MySQLGraph(connection));
g.setMysql(true);
} else {
fixGraphDataMem(new MemGraph());
g.setMysql(false);
}
return g;
}
private synchronized static void fixGraphData(Graph graph) {
try {
g = new SingletonGraph(new PAP(
new GraphAdmin(graph),
new ProhibitionsAdmin(new MySQLProhibitions(connection)),
new ObligationsAdmin(new MemObligations())
));
System.out.println("MySQLGraph");
superContext = null;
activePCs = new HashSet<>();
for (Node n : graph.getNodes()) {
if (n.getProperties().get("namespace") != null && n.getProperties().get("namespace").equals("super")) {
switch (n.getType()) {
case OA:
System.out.println("Super OA: " + n.getName());
superOAId = n.getName();
break;
case UA:
if (n.getName().equals("super_ua2")) {
System.out.println("Super UA: " + n.getName());
superUAId = n.getName();
}
break;
case U:
System.out.println("Super U: " + n.getName());
superContext = new UserContext(n.getName(), rand.toString());
break;
case PC:
System.out.println("Super PC: " + n.getName());
superPCId = n.getName();
break;
}
}
if (n.getType().equals(NodeType.PC)) {
activePCs.add(new PolicyClassWithActive(n));
}
}
OperationSet resourceOps = new OperationSet();
resourceOps.add(Operations.READ);
resourceOps.add(Operations.WRITE);
resourceOps.add(Operations.OBJECT_ACCESS);
getPDP().setResourceOps(resourceOps);
} catch (PMException e) {
e.printStackTrace();
}
}
我阅读到在 Vaadin 上使用 MySQL 是一个常见的问题,它会在某种程度上减慢用户界面,而且一些 Vaadin 方法似乎更倾向于惰性加载。然而,即使使用了这些特定的方法,我也不知道如何优化客户端方面。是否有人曾经遇到过这种情况?如何进行优化?
谢谢。
附注:我使用 synchronized static,因为我只想在项目中有一个图形实例。
英文:
I have a client vaadin app that use in-memory DB and I added the possibility to switch to mysql. I use the backend as an API. All operations using those mysql method instead of the in memory DB take so much time (at least 30s each) on client side but are still instantaneous on mysql side.
public SingletonGraph updateGraph (boolean isMySQL){
g = null;
if (isMySQL) {
fixGraphData(new MySQLGraph(connection));
g.setMysql(true);
} else {
fixGraphDataMem(new MemGraph());
g.setMysql(false);
}
return g;
}
private synchronized static void fixGraphData(Graph graph) {
try {
g = new SingletonGraph(new PAP(
new GraphAdmin(graph),
new ProhibitionsAdmin(new MySQLProhibitions(connection)),
new ObligationsAdmin(new MemObligations())
));
System.out.println("MySQLGraph");
superContext = null;
activePCs = new HashSet<>();
for (Node n : graph.getNodes()) {
if (n.getProperties().get("namespace") != null && n.getProperties().get("namespace").equals("super")) {
switch (n.getType()) {
case OA:
System.out.println("Super OA: " + n.getName());
superOAId = n.getName();
break;
case UA:
if (n.getName().equals("super_ua2")) {
System.out.println("Super UA: " + n.getName());
superUAId = n.getName();
}
break;
case U:
System.out.println("Super U: " + n.getName());
superContext = new UserContext(n.getName(), rand.toString());
break;
case PC:
System.out.println("Super PC: " + n.getName());
superPCId = n.getName();
break;
}
}
if (n.getType().equals(NodeType.PC)) {
activePCs.add(new PolicyClassWithActive(n));
}
}
OperationSet resourceOps = new OperationSet();
resourceOps.add(Operations.READ);
resourceOps.add(Operations.WRITE);
resourceOps.add(Operations.OBJECT_ACCESS);
getPDP().setResourceOps(resourceOps);
} catch (PMException e) {
e.printStackTrace();
}
}
I read that it is a common issue on Vaadin that using mysql somehow slow the UI and that some vaadin method favors a lazy loading however even using those specific method I have no idea how to optimize the client side. Has anyone ever experiment that ? How to optimize it ?
Thank you.
Ps : I use synchronized static as I only want one instance of the graph in my project.
专注分享java语言的经验与见解,让所有开发者获益!
评论