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 { ...@@ -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.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" + "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" + "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" + "WHERE n.node_id = id_from_vos_path(?)\n"
+ "ORDER BY vos_path"; + "ORDER BY vos_path";
...@@ -116,7 +116,6 @@ public class NodeDAO { ...@@ -116,7 +116,6 @@ public class NodeDAO {
ps.setString(++i, path); ps.setString(++i, path);
ps.setString(++i, path); ps.setString(++i, path);
ps.setString(++i, "/".equals(path) ? "" : "/"); ps.setString(++i, "/".equals(path) ? "" : "/");
ps.setString(++i, "/".equals(path) ? "" : ".");
ps.setString(++i, path); ps.setString(++i, path);
return ps; return ps;
}, (row, index) -> { }, (row, index) -> {
...@@ -174,7 +173,7 @@ public class NodeDAO { ...@@ -174,7 +173,7 @@ public class NodeDAO {
boolean isLinkNode = newNode instanceof LinkNode; boolean isLinkNode = newNode instanceof LinkNode;
// If is link ignore recursive: LinkNodes are supposed to be childless // If is link ignore recursive: LinkNodes are supposed to be childless
if (recursive && !isLinkNode) { if (recursive && !isLinkNode) {
updatePermissionsRecursively(newNode, vosPath); updatePermissionsRecursively(newNode, vosPath);
} else { } else {
jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> {
...@@ -185,7 +184,7 @@ public class NodeDAO { ...@@ -185,7 +184,7 @@ public class NodeDAO {
if (isLinkNode) { if (isLinkNode) {
sql += ", target = ?\n"; sql += ", target = ?\n";
} }
sql += "WHERE node_id = id_from_vos_path(?)\n"; sql += "WHERE node_id = id_from_vos_path(?)\n";
PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql);
...@@ -317,8 +316,8 @@ public class NodeDAO { ...@@ -317,8 +316,8 @@ public class NodeDAO {
} }
public void renameNode(Long nodeId, String name) { public void renameNode(Long nodeId, String name) {
String sql = "UPDATE node SET name = ?\n, os_name = COALESCE(os_name, name)" String sql = "UPDATE node SET name = ?, os_name = COALESCE(os_name, name) "
+ "WHERE path ~ ('*.' || ?)::lquery"; + "WHERE node_id = ?";
jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql);
...@@ -345,7 +344,7 @@ public class NodeDAO { ...@@ -345,7 +344,7 @@ public class NodeDAO {
return ps; return ps;
}); });
} }
public void copyBranch(String sourceVosPath, String destVosPath) { public void copyBranch(String sourceVosPath, String destVosPath) {
String destVosParentPath = NodeUtils.getParentPath(destVosPath); String destVosParentPath = NodeUtils.getParentPath(destVosPath);
...@@ -392,14 +391,14 @@ public class NodeDAO { ...@@ -392,14 +391,14 @@ public class NodeDAO {
+ "copied_nodes_paths AS (" + "copied_nodes_paths AS ("
+ cteCopiedNodesPaths + ")\n" + cteCopiedNodesPaths + ")\n"
+ parentSelect; + parentSelect;
jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, destVosParentPath); ps.setString(1, destVosParentPath);
ps.setString(2, destName); ps.setString(2, destName);
ps.setString(3, sourceVosPath); ps.setString(3, sourceVosPath);
return ps; return ps;
}); });
} }
public boolean isBranchBusy(long parentNodeId) { public boolean isBranchBusy(long parentNodeId) {
...@@ -413,8 +412,10 @@ public class NodeDAO { ...@@ -413,8 +412,10 @@ public class NodeDAO {
} }
public void setBranchJobId(Long rootNodeId, String jobId) { public void setBranchJobId(Long rootNodeId, String jobId) {
String sql = "UPDATE node SET job_id = ?\n" String sql = "UPDATE node c SET job_id = ? "
+ "WHERE path ~ ('*.' || ? || '.*')::lquery"; + "FROM node r "
+ "WHERE r.node_id = ? "
+ "AND r.path @> c.path";
jdbcTemplate.update(conn -> { jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql); 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