use of com.enonic.xp.node.NodeVersionQuery in project xp by enonic.
the class NodeServiceImpl method findVersions.
@Override
public NodeVersionQueryResult findVersions(final GetNodeVersionsParams params) {
verifyContext();
final NodeVersionQuery query = NodeVersionQuery.create().size(params.getSize()).from(params.getFrom()).nodeId(params.getNodeId()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
return FindNodeVersionsCommand.create().query(query).searchService(this.nodeSearchService).build().execute();
}
use of com.enonic.xp.node.NodeVersionQuery in project xp by enonic.
the class IsBlobUsedByVersionCommand method execute.
public boolean execute() {
final NodeVersionQuery query = createQuery();
final NodeVersionQueryResult versions = nodeService.findVersions(query);
return versions.getTotalHits() > 0;
}
use of com.enonic.xp.node.NodeVersionQuery in project xp by enonic.
the class SegmentVacuumCommand method isRepositoryToKeep.
private boolean isRepositoryToKeep(final RepositoryId repositoryId) {
return repositoryPresenceMap.computeIfAbsent(repositoryId, key -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Repository [" + repositoryId + "] not found in the list of current repository");
}
// If repository is not present, find if there is an old version more recent than the threshold
final Context systemContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(SystemConstants.SYSTEM_REPO_ID).branch(SystemConstants.BRANCH_SYSTEM).build();
final Instant since = Instant.now().minusMillis(params.getAgeThreshold());
final NodeVersionQuery findRecentVersionsQuery = NodeVersionQuery.create().nodeId(NodeId.from(repositoryId.toString())).addQueryFilter(RangeFilter.create().fieldName(VersionIndexPath.TIMESTAMP.getPath()).from(ValueFactory.newDateTime(since)).build()).size(0).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
final NodeVersionQueryResult result = systemContext.callWith(() -> nodeService.findVersions(findRecentVersionsQuery));
if (result.getTotalHits() > 0 && LOG.isDebugEnabled()) {
LOG.debug("Recent versions of the repository entry found");
}
return result.getTotalHits() > 0;
});
}
use of com.enonic.xp.node.NodeVersionQuery in project xp by enonic.
the class VersionTableVacuumCommand method doProcessRepository.
private void doProcessRepository(final Repository repository) {
int counter = 0;
NodeVersionId lastVersionId = null;
NodeVersionQuery query = createQuery(lastVersionId);
NodeVersionQueryResult versionsResult = nodeService.findVersions(query);
long hits = versionsResult.getHits();
final long totalHits = versionsResult.getTotalHits();
if (listener != null) {
listener.stepBegin(repository.getId().toString(), totalHits);
}
while (hits > 0) {
final List<NodeVersionId> versionsToDelete = new ArrayList<>();
final Set<BlobKey> nodeBlobToCheckSet = new HashSet<>();
final Set<BlobKey> binaryBlobToCheckSet = new HashSet<>();
final NodeVersionsMetadata versions = versionsResult.getNodeVersionsMetadata();
for (NodeVersionMetadata version : versions) {
final boolean toDelete = processVersion(repository, version);
if (toDelete) {
result.deleted();
versionsToDelete.add(version.getNodeVersionId());
nodeBlobToCheckSet.add(version.getNodeVersionKey().getNodeBlobKey());
binaryBlobToCheckSet.addAll(version.getBinaryBlobKeys().getSet());
} else {
result.inUse();
}
lastVersionId = version.getNodeVersionId();
counter++;
}
versionService.delete(versionsToDelete, InternalContext.from(ContextAccessor.current()));
nodeBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.NODE_BLOB_KEY)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.NODE_SEGMENT_LEVEL, blobKey));
binaryBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.BINARY_BLOB_KEYS)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.BINARY_SEGMENT_LEVEL, blobKey));
query = createQuery(lastVersionId);
versionsResult = nodeService.findVersions(query);
hits = versionsResult.getHits();
}
if (listener != null) {
listener.processed(counter);
}
}
use of com.enonic.xp.node.NodeVersionQuery in project xp by enonic.
the class ApplyNodePermissionsCommandTest method assertVersions.
private void assertVersions(final Node node) {
final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
final NodeVersionQueryResult versions = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
assertEquals(2, versions.getHits());
final Iterator<NodeVersionMetadata> iterator = versions.getNodeVersionsMetadata().iterator();
assertTrue(iterator.next().getTimestamp().isAfter(iterator.next().getTimestamp()));
}
Aggregations