Skip to content

Commit

Permalink
Deleted version based on deactivation ts #10794
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Dec 11, 2024
1 parent eac89bd commit d670243
Showing 1 changed file with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,19 @@ private void doProcessRepository( final Repository repository )
final boolean toDelete = processVersion( repository, version );
if ( toDelete )
{
LOG.debug( "Version's timestamp = '{}', nodeId = '{}', versionId = '{}'", version.getTimestamp(), version.getNodeId(),
version.getNodeVersionId() );
result.deleted();
versionService.delete( version.getNodeVersionId(), context );
nodeBlobToCheckSet.add( version.getNodeVersionKey().getNodeBlobKey() );
binaryBlobToCheckSet.addAll( version.getBinaryBlobKeys().getSet() );
if ( checkThatVersionIsOld( version, ageThreshold ) )
{
LOG.debug( "Version's timestamp = '{}', nodeId = '{}', versionId = '{}'", version.getTimestamp(),
version.getNodeId(), version.getNodeVersionId() );
result.deleted();
versionService.delete( version.getNodeVersionId(), context );
nodeBlobToCheckSet.add( version.getNodeVersionKey().getNodeBlobKey() );
binaryBlobToCheckSet.addAll( version.getBinaryBlobKeys().getSet() );
}
else
{
result.inUse();

Check warning on line 159 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L159

Added line #L159 was not covered by tests
}
}
else
{
Expand Down Expand Up @@ -257,6 +264,54 @@ private NodeVersionQuery createQuery( NodeVersionId lastVersionId, Instant ageTh
.build();
}

private boolean checkThatVersionIsOld( NodeVersionMetadata previousVersion, Instant ageThreshold )
{
final NodeVersionQuery query = findNextVersion( previousVersion.getNodeVersionId(), ageThreshold );
final NodeVersionQueryResult versionsResult = nodeService.findVersions( query );
final long hits = versionsResult.getHits();

if ( hits == 0 )
{
LOG.debug( "No next version found for version [{}].", previousVersion.getNodeVersionId() );
return true;
}

final NodeVersionMetadata nextVersion = versionsResult.getNodeVersionsMetadata().iterator().next();

Check warning on line 279 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L279

Added line #L279 was not covered by tests

final Instant tsOfPrevVersion = previousVersion.getTimestamp();
final Instant tsOfNextVersion = nextVersion.getTimestamp();

Check warning on line 282 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L281-L282

Added lines #L281 - L282 were not covered by tests

final boolean shouldBeDeleted = tsOfPrevVersion.isBefore( ageThreshold ) && ageThreshold.isBefore( tsOfNextVersion );

LOG.debug(

Check warning on line 286 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L286

Added line #L286 was not covered by tests
"Checking if version [{}] should be deleted. tsOfPrevVersion: {}, tsOfNextVersion: {}, ageThreshold: {}. Should be deleted: {}",
previousVersion.getNodeVersionId(), tsOfPrevVersion, tsOfNextVersion, ageThreshold, shouldBeDeleted );

Check warning on line 288 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L288

Added line #L288 was not covered by tests

return shouldBeDeleted;

Check warning on line 290 in modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java

View check run for this annotation

Codecov / codecov/patch

modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java#L290

Added line #L290 was not covered by tests
}

private NodeVersionQuery findNextVersion( NodeVersionId lastVersionId, Instant ageThreshold )
{
final NodeVersionQuery.Builder builder = NodeVersionQuery.create();

if ( lastVersionId != null )
{
final RangeFilter versionIdFilter = RangeFilter.create()
.fieldName( VersionIndexPath.VERSION_ID.getPath() )
.gt( ValueFactory.newString( lastVersionId.toString() ) )
.build();
builder.addQueryFilter( versionIdFilter );
}

final RangeFilter filter =
RangeFilter.create().fieldName( VersionIndexPath.TIMESTAMP.getPath() ).from( ValueFactory.newDateTime( ageThreshold ) ).build();

return builder.addQueryFilter( filter )
.addOrderBy( FieldOrderExpr.create( VersionIndexPath.TIMESTAMP, OrderExpr.Direction.ASC ) )
.size( 1 )
.build();
}

public static final class Builder
{
private Clock clock;
Expand Down

0 comments on commit d670243

Please sign in to comment.