Skip to content

Commit

Permalink
Align @Indexed(expireAfter) with expireAfterSeconds.
Browse files Browse the repository at this point in the history
This commit fixes an issue where expireAfter=0s behaves differently from expireAfterSeconds=0 where the former would not be applied.

Closes #4844
Original pull request: #4848
  • Loading branch information
christophstrobl authored and mp911de committed Dec 10, 2024
1 parent d6fe3c0 commit ad39a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ protected IndexDefinitionHolder createIndexDefinition(String dotPath, String col

Duration timeout = computeIndexTimeout(index.expireAfter(),
() -> getEvaluationContextForProperty(persistentProperty.getOwner()));
if (!timeout.isZero() && !timeout.isNegative()) {
if (!timeout.isNegative()) {
indexDefinition.expire(timeout);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ public void shouldResolveTimeoutFromString() {
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 600L);
}

@Test // GH-4844
public void shouldResolveZeroTimeoutFromString() {

List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
WithExpireAfterZeroSecondsAsPlainString.class);

assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 0L);
}

@Test // DATAMONGO-2112
public void shouldResolveTimeoutFromIso8601String() {

Expand Down Expand Up @@ -383,6 +392,11 @@ class WithExpireAfterAsPlainString {
@Indexed(expireAfter = "10m") String withTimeout;
}

@Document
class WithExpireAfterZeroSecondsAsPlainString {
@Indexed(expireAfter = "0s") String withTimeout;
}

@Document
class WithIso8601Style {
@Indexed(expireAfter = "P1D") String withTimeout;
Expand Down

0 comments on commit ad39a43

Please sign in to comment.