Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-21922: Introduce methods to fetch a subset of revisions in XWikiVersioningStoreInterface #2967

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.Date;

import org.xwiki.stability.Unstable;

/**
* information about document versions used to retreive a set of document versions.
*
Expand Down Expand Up @@ -160,4 +162,21 @@ public void setIncludeMinorVersions(boolean includeMinorVersions)
{
this.includeMinorVersions = includeMinorVersions;
}

/**
* Checks that the criteria are all-inclusive.
*
* @return false if some revisions might be filtered out by these criteria, true otherwise.
* @since 15.10.8
* @since 16.2.0RC1
*/
@Unstable
public boolean isAllInclusive()
{
return this.includeMinorVersions
&& this.getAuthor().isEmpty()
&& this.getRange().getSize() == 0
pjeanjean marked this conversation as resolved.
Show resolved Hide resolved
&& this.getPeriod().getStart() == Long.MIN_VALUE
&& this.getPeriod().getEnd() == Long.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ private XWikiDocumentArchive getXWikiDocumentArchive(XWikiDocument doc, Revision
XWikiContext inputxcontext) throws XWikiException
{
XWikiDocumentArchive archiveDoc = doc.getDocumentArchive();
if (archiveDoc != null) {
// We only retrieve a cached archive if we want a complete one.
if (archiveDoc != null && criteria.isAllInclusive()) {
return archiveDoc;
}

Expand All @@ -160,7 +161,10 @@ private XWikiDocumentArchive getXWikiDocumentArchive(XWikiDocument doc, Revision
}
archiveDoc = new XWikiDocumentArchive(doc.getDocumentReference().getWikiReference(), doc.getId());
loadXWikiDocArchive(archiveDoc, criteria, context);
doc.setDocumentArchive(archiveDoc);
// We only store the archive if it is a complete one.
if (criteria.isAllInclusive()) {
doc.setDocumentArchive(archiveDoc);
}
} finally {
context.setWikiId(db);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ private void applyRange(Range range)
int start = range.getStart();
int size = range.getSize();

if (start > 0 || start == 0 && size >= 0) {
if (start > 0 && size != 0 || start == 0 && size > 0) {
this.criteriaQuery.orderBy(this.builder.asc(this.root.get(FIELD_ID).get(FIELD_VERSION1)),
this.builder.asc(this.root.get(FIELD_ID).get(FIELD_VERSION2)));
} else {
} else if (size != 0) {
this.criteriaQuery.orderBy(this.builder.desc(this.root.get(FIELD_ID).get(FIELD_VERSION1)),
this.builder.desc(this.root.get(FIELD_ID).get(FIELD_VERSION2)));
start = -start;
Expand All @@ -133,10 +133,10 @@ private void applyRange(Range range)

this.query = this.session.createQuery(this.criteriaQuery);

if (size >= 0) {
if (size > 0) {
this.query.setFirstResult(start);
this.query.setMaxResults(size);
} else {
} else if (size < 0) {
int newStart = Math.max(0, start + size);
this.query.setFirstResult(newStart);
this.query.setMaxResults(start - newStart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -326,4 +328,18 @@ void testRCSNodeInfoQueryWithRange(int startRange, int sizeRange, int start, int
verify(this.queryNodeInfo).setFirstResult(start);
verify(this.queryNodeInfo).setMaxResults(size);
}

@Test
void testRCSNodeInfoQueryWithAllRange()
{
// When the size of the range is 0 (ALL), there should be no filtering done.
RevisionCriteria criteria = new RevisionCriteriaFactory().createRevisionCriteria(true);
for (int start : new int[] {-10, 0, 10}) {
criteria.setRange(RangeFactory.createRange(start, 0));
VersioningStoreQueryFactory.getRCSNodeInfoQuery(this.session, 42L, criteria);
}
verify(this.criteriaQueryNodeInfo, never()).orderBy(Mockito.<Order[]>any());
verify(this.queryNodeInfo, never()).setFirstResult(anyInt());
verify(this.queryNodeInfo, never()).setMaxResults(anyInt());
}
}
Loading