Skip to content

Commit

Permalink
feat: remove updateExpirationTime method
Browse files Browse the repository at this point in the history
  • Loading branch information
pangdayuan1 committed Sep 9, 2024
1 parent 0912ac2 commit e37c164
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
import com.arextest.storage.model.Constants;
import com.arextest.storage.repository.ProviderNames;
import com.arextest.storage.repository.RepositoryProvider;
import com.arextest.storage.utils.TimeUtils;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

/**
* The rolling provider used by default, which means auto deleted the records after TTL index
Expand Down Expand Up @@ -83,10 +80,6 @@ public Iterable<AREXQueryMocker> queryRecordList(MockCategoryType categoryType,
public Iterable<AREXQueryMocker> queryRecordList(MockCategoryType category, String recordId, String[] fieldNames) {
Criteria criteria = buildRecordIdFilter(category, recordId);

if (Objects.equals(this.providerName, ProviderNames.DEFAULT)) {
updateExpirationTime(criteria, getCollectionName(category));
}

Query query = new Query(criteria);
if (ArrayUtils.isNotEmpty(fieldNames)) {
String[] mappedFieldNames = Arrays.stream(fieldNames)
Expand All @@ -101,27 +94,6 @@ public Iterable<AREXQueryMocker> queryRecordList(MockCategoryType category, Stri
return new AttachmentCategoryIterable(category, iterable);
}

private void updateExpirationTime(Criteria criteria, String collectionName) {
long currentTimeMillis = System.currentTimeMillis();
long allowedLastMills = TimeUtils.getTodayFirstMills() +
properties.getAllowReRunDays() * TimeUtils.ONE_DAY;

Criteria finalCriteria = new Criteria().andOperator(
criteria,
new Criteria().orOperator(
Criteria.where(AbstractMocker.Fields.expirationTime).lt(new Date(allowedLastMills)),
Criteria.where(AbstractMocker.Fields.expirationTime).exists(false)
)
);

// Add different minutes to avoid the same expiration time
Update update = new Update();
update.set(AbstractMocker.Fields.expirationTime,
new Date(allowedLastMills + currentTimeMillis % TimeUtils.ONE_HOUR));
update.set(AbstractMocker.Fields.updateTime, new Date(currentTimeMillis));
mongoTemplate.updateMulti(new Query(finalCriteria), update, collectionName);
}

private Criteria buildRecordIdFilter(MockCategoryType categoryType, String value) {
if (categoryType.isEntryPoint()) {
return Criteria.where(AbstractMocker.Fields.id).is(value);
Expand Down
4 changes: 4 additions & 0 deletions arex-storage-web-api/src/main/resources/log4j2-dev.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
</Appenders>

<Loggers>
<Logger level="WARN" name="org.springframework.data.mongodb.core.convert.QueryMapper">
<AppenderRef ref="Mongo4"/>
<AppenderRef ref="Prometheus"/>
</Logger>
<Logger level="INFO" name="com.arextest">
<AppenderRef ref="Mongo4"/>
</Logger>
Expand Down
4 changes: 4 additions & 0 deletions arex-storage-web-api/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
</Appenders>

<Loggers>
<Logger level="WARN" name="org.springframework.data.mongodb.core.convert.QueryMapper">
<AppenderRef ref="Mongo4"/>
<AppenderRef ref="Prometheus"/>
</Logger>
<Logger level="INFO" name="com.arextest.storage">
<AppenderRef ref="Mongo4"/>
<AppenderRef ref="Prometheus"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
</profiles>

<properties>
<revision>1.3.2</revision>
<revision>1.3.3</revision>
<commons-lang3.version>3.3.2</commons-lang3.version>
<java.version>1.8</java.version>

Expand Down

0 comments on commit e37c164

Please sign in to comment.