From 0444f89da17de264fc27771020e2ef70b9bb770d Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Fri, 24 May 2024 11:23:50 +0200 Subject: [PATCH] XWIKI-22182: Page history is missing after a page containing attachments is moved Revert "XWIKI-9046: Renaming a document holding a lot of revisions can lead to an OutOfMemory exception (#2926)" This reverts commit 8e509b70136b2c64359c49ad64ce128874a9c4c0. The solution provided in this commit wasn't taking into account usecases when the doc wasn't saved in DB yet, e.g. like in case of renaming. Also the solution is not good since we actually never set the archive in doc in case of criteria not all inclusive, and if it had worked it would have been a problem since we'd have kept only latest revision and lost the remaining of the history when saving docs. All in all we need another solution. (cherry picked from commit 03d3ebeaea072fdc4e17f5aff0a5f7c0e5e6de8f) --- .../store/XWikiHibernateVersioningStore.java | 7 +- .../XWikiHibernateVersioningStoreTest.java | 111 ------------------ 2 files changed, 1 insertion(+), 117 deletions(-) delete mode 100644 xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/XWikiHibernateVersioningStoreTest.java diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java index 94ffdbf1ec4a..6d56376ca6bb 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java @@ -38,7 +38,6 @@ import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.criteria.impl.RangeFactory; import com.xpn.xwiki.criteria.impl.RevisionCriteria; import com.xpn.xwiki.criteria.impl.RevisionCriteriaFactory; import com.xpn.xwiki.doc.XWikiAttachment; @@ -289,11 +288,7 @@ public void updateXWikiDocArchive(XWikiDocument doc, boolean bTransaction, XWiki XWikiContext context = getExecutionXContext(inputxcontext, true); try { - RevisionCriteria criteria = new RevisionCriteria(); - criteria.setIncludeMinorVersions(true); - criteria.setRange(RangeFactory.getLAST()); - - XWikiDocumentArchive archiveDoc = getXWikiDocumentArchive(doc, criteria, context); + XWikiDocumentArchive archiveDoc = getXWikiDocumentArchive(doc, context); UserReferenceSerializer userReferenceSerializer = Utils.getComponent( new DefaultParameterizedType(null, UserReferenceSerializer.class, String.class)); String author = userReferenceSerializer.serialize(doc.getAuthors().getOriginalMetadataAuthor()); diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/XWikiHibernateVersioningStoreTest.java b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/XWikiHibernateVersioningStoreTest.java deleted file mode 100644 index c3ecbd95a0cf..000000000000 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/XWikiHibernateVersioningStoreTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.store; - -import java.util.List; - -import org.hibernate.query.Query; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.Spy; -import org.xwiki.model.document.DocumentAuthors; -import org.xwiki.model.reference.DocumentReference; -import org.xwiki.test.junit5.mockito.InjectMockComponents; -import org.xwiki.test.junit5.mockito.MockComponent; -import org.xwiki.user.UserReferenceSerializer; - -import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.criteria.impl.RevisionCriteria; -import com.xpn.xwiki.doc.XWikiDocument; -import com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo; -import com.xpn.xwiki.store.hibernate.query.VersioningStoreQueryFactory; -import com.xpn.xwiki.test.junit5.mockito.OldcoreTest; -import com.xpn.xwiki.test.reference.ReferenceComponentList; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.when; - -/** - * Unit tests for {@link XWikiHibernateVersioningStore}. - * - * @version $Id$ - */ -@ReferenceComponentList -@OldcoreTest -public class XWikiHibernateVersioningStoreTest -{ - @Spy - @InjectMockComponents - private XWikiHibernateVersioningStore versioningStore; - - @MockComponent - private UserReferenceSerializer userReferenceSerializer; - - @Mock - private Query nodeInfoQuery; - - @Mock - private XWikiDocument document; - - @Mock - private DocumentAuthors authors; - - @Captor - private ArgumentCaptor revisionCriteria; - - @BeforeEach - void setUp() throws XWikiException - { - when(this.nodeInfoQuery.getResultList()).thenReturn(List.of()); - - DocumentReference documentReference = new DocumentReference("xwiki", "test", "TestPage"); - when(this.document.getDocumentReference()).thenReturn(documentReference); - when(this.document.getAuthors()).thenReturn(this.authors); - when(this.document.toXML(null)).thenReturn("<"); - } - - /** - * This test checks that whenever the archive gets updated, only a single revision is ever fetched from the - * versioning store. - */ - @Test - void checkLoadedRevisionsDuringArchiveUpdate() throws XWikiException - { - doNothing().when(this.versioningStore).saveXWikiDocArchive(any(), anyBoolean(), any()); - - try (MockedStatic mockedQueryFactory = mockStatic(VersioningStoreQueryFactory.class)) { - mockedQueryFactory.when( - () -> VersioningStoreQueryFactory.getRCSNodeInfoQuery(any(), anyLong(), this.revisionCriteria.capture()) - ).thenReturn(this.nodeInfoQuery); - - this.versioningStore.updateXWikiDocArchive(this.document, false, null); - assertEquals(1, this.revisionCriteria.getValue().getRange().getAbsoluteSize()); - } - } -}