Detach counting of subnodes from the size() method to exactly mirror the behaviour of SubnodeList.
This commit is contained in:
parent
ff35a07fa3
commit
b637cf7333
1 changed files with 8 additions and 15 deletions
|
@ -15,18 +15,17 @@ import java.util.*;
|
||||||
|
|
||||||
public class SegmentedSubnodeList extends SubnodeList {
|
public class SegmentedSubnodeList extends SubnodeList {
|
||||||
|
|
||||||
transient Segment[] segments;
|
transient Segment[] segments = null;
|
||||||
static int SEGLENGTH = 1000;
|
static int SEGLENGTH = 1000;
|
||||||
|
|
||||||
transient long lastSubnodeCount = 0;
|
transient private int subnodeCount = -1;
|
||||||
transient int subnodeCount = -1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new subnode list
|
* Creates a new subnode list
|
||||||
* @param node the node we belong to
|
* @param node the node we belong to
|
||||||
*/
|
*/
|
||||||
public SegmentedSubnodeList(Node node) {
|
public SegmentedSubnodeList(Node node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,14 +206,17 @@ public class SegmentedSubnodeList extends SubnodeList {
|
||||||
|
|
||||||
protected synchronized void update() {
|
protected synchronized void update() {
|
||||||
if (!hasRelationalNodes()) {
|
if (!hasRelationalNodes()) {
|
||||||
|
segments = null;
|
||||||
super.update();
|
super.update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// also reload if the type mapping has changed.
|
// also reload if the type mapping has changed.
|
||||||
long lastChange = getLastSubnodeChange();
|
long lastChange = getLastSubnodeChange();
|
||||||
if (lastChange != lastSubnodeFetch) {
|
if (lastChange != lastSubnodeFetch) {
|
||||||
float size = size();
|
// count nodes in db without fetching anything
|
||||||
if (size > SEGLENGTH) {
|
subnodeCount = node.nmgr.countNodes(node, getSubnodeRelation());
|
||||||
|
if (subnodeCount > SEGLENGTH) {
|
||||||
|
float size = subnodeCount;
|
||||||
int nsegments = (int) Math.ceil(size / SEGLENGTH);
|
int nsegments = (int) Math.ceil(size / SEGLENGTH);
|
||||||
int remainder = (int) size % SEGLENGTH;
|
int remainder = (int) size % SEGLENGTH;
|
||||||
segments = new Segment[nsegments];
|
segments = new Segment[nsegments];
|
||||||
|
@ -239,15 +241,6 @@ public class SegmentedSubnodeList extends SubnodeList {
|
||||||
if (!hasRelationalNodes() || segments == null) {
|
if (!hasRelationalNodes() || segments == null) {
|
||||||
return super.size();
|
return super.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Relation rel = getSubnodeRelation();
|
|
||||||
long lastChange = getLastSubnodeChange();
|
|
||||||
|
|
||||||
if (lastChange != lastSubnodeCount || subnodeCount < 0) {
|
|
||||||
// count nodes in db without fetching anything
|
|
||||||
subnodeCount = node.nmgr.countNodes(node, rel);
|
|
||||||
lastSubnodeCount = lastChange;
|
|
||||||
}
|
|
||||||
return subnodeCount;
|
return subnodeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue