use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class FindContentVersionsCommand method doGetContentVersions.
private FindContentVersionsResult doGetContentVersions() {
this.nodeService.refresh(RefreshMode.STORAGE);
final NodeId nodeId = NodeId.from(this.contentId);
final NodeVersionQueryResult nodeVersionQueryResult = nodeService.findVersions(GetNodeVersionsParams.create().nodeId(nodeId).from(this.from).size(this.size).build());
final FindContentVersionsResult.Builder findContentVersionsResultBuilder = FindContentVersionsResult.create().hits(nodeVersionQueryResult.getHits()).totalHits(nodeVersionQueryResult.getTotalHits()).from(nodeVersionQueryResult.getFrom()).size(nodeVersionQueryResult.getSize());
final ContentVersionFactory contentVersionFactory = new ContentVersionFactory(this.nodeService);
final ContentVersions contentVersions = contentVersionFactory.create(nodeId, nodeVersionQueryResult.getNodeVersionsMetadata());
findContentVersionsResultBuilder.contentVersions(contentVersions);
return findContentVersionsResultBuilder.build();
}
use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.
the class RepoDumper method dumpVersions.
private void dumpVersions(final Collection<NodeId> dumpedNodes) {
writer.openVersionsMeta(repository.getId());
try {
for (NodeId nodeId : dumpedNodes) {
final VersionsDumpEntry.Builder builder = VersionsDumpEntry.create(nodeId);
final NodeVersionQueryResult versions = getVersions(nodeId);
for (final NodeVersionMetadata metaData : versions.getNodeVersionsMetadata()) {
doStoreVersion(builder, metaData, this.dumpResult);
this.dumpResult.addedVersion();
}
writer.writeVersionsEntry(builder.build());
}
} finally {
writer.closeMeta();
}
}
use of com.enonic.xp.node.NodeVersionQueryResult 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.NodeVersionQueryResult 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.NodeVersionQueryResult 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);
}
}
Aggregations