Commit a64d0815 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Optimized some queries (tested with 10M+ nodes)

parent adcba2fb
......@@ -106,7 +106,7 @@ public class NodeDAO {
+ "c.type, c.async_trans, c.sticky, c.job_id IS NOT NULL AS busy_state, c.creator_id, c.group_read, c.group_write,\n"
+ "c.is_public, c.content_length, c.created_on, c.last_modified, c.accept_views, c.provide_views, c.quota, c.content_md5, c.target\n"
+ "FROM node n\n"
+ "JOIN node c ON c.path ~ (n.path::varchar || ? || '*{1}')::lquery OR c.path = n.path\n"
+ "JOIN node c ON c.parent_path = n.path OR c.path = n.path\n"
+ "WHERE n.node_id = id_from_vos_path(?)\n"
+ "ORDER BY vos_path";
......@@ -116,7 +116,6 @@ public class NodeDAO {
ps.setString(++i, path);
ps.setString(++i, path);
ps.setString(++i, "/".equals(path) ? "" : "/");
ps.setString(++i, "/".equals(path) ? "" : ".");
ps.setString(++i, path);
return ps;
}, (row, index) -> {
......@@ -174,7 +173,7 @@ public class NodeDAO {
boolean isLinkNode = newNode instanceof LinkNode;
// If is link ignore recursive: LinkNodes are supposed to be childless
if (recursive && !isLinkNode) {
if (recursive && !isLinkNode) {
updatePermissionsRecursively(newNode, vosPath);
} else {
jdbcTemplate.update(conn -> {
......@@ -185,7 +184,7 @@ public class NodeDAO {
if (isLinkNode) {
sql += ", target = ?\n";
}
sql += "WHERE node_id = id_from_vos_path(?)\n";
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -317,8 +316,8 @@ public class NodeDAO {
}
public void renameNode(Long nodeId, String name) {
String sql = "UPDATE node SET name = ?\n, os_name = COALESCE(os_name, name)"
+ "WHERE path ~ ('*.' || ?)::lquery";
String sql = "UPDATE node SET name = ?, os_name = COALESCE(os_name, name) "
+ "WHERE node_id = ?";
jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -345,7 +344,7 @@ public class NodeDAO {
return ps;
});
}
public void copyBranch(String sourceVosPath, String destVosPath) {
String destVosParentPath = NodeUtils.getParentPath(destVosPath);
......@@ -392,14 +391,14 @@ public class NodeDAO {
+ "copied_nodes_paths AS ("
+ cteCopiedNodesPaths + ")\n"
+ parentSelect;
jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, destVosParentPath);
ps.setString(2, destName);
ps.setString(3, sourceVosPath);
return ps;
});
});
}
public boolean isBranchBusy(long parentNodeId) {
......@@ -413,8 +412,10 @@ public class NodeDAO {
}
public void setBranchJobId(Long rootNodeId, String jobId) {
String sql = "UPDATE node SET job_id = ?\n"
+ "WHERE path ~ ('*.' || ? || '.*')::lquery";
String sql = "UPDATE node c SET job_id = ? "
+ "FROM node r "
+ "WHERE r.node_id = ? "
+ "AND r.path @> c.path";
jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment