Source:
public List<SmartAlarmHistory> getSmartAlarmHistoryByScheduleTime(final long accountId, final DateTime start, final DateTime end){ final Map<String, Condition> queryConditions = new HashMap<String, Condition>(); final Condition selectDateCondition = new Condition() .withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList(new AttributeValue().withS(start.toString(DATETIME_FORMAT)), new AttributeValue().withS(end.toString(DATETIME_FORMAT))); queryConditions.put(CURRENT_TIME_ATTRIBUTE_NAME, selectDateCondition); final Condition selectAccountIdCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(accountId))); queryConditions.put(ACCOUNT_ID_ATTRIBUTE_NAME, selectAccountIdCondition); Map<String, AttributeValue> lastEvaluatedKey = null; final List<SmartAlarmHistory> history = new ArrayList<>(); final Collection<String> targetAttributeSet = new HashSet<String>(); Collections.addAll(targetAttributeSet, ACCOUNT_ID_ATTRIBUTE_NAME, CURRENT_TIME_ATTRIBUTE_NAME, EXPECTED_RING_TIME_ATTRIBUTE_NAME, SMART_RING_TIME_ATTRIBUTE_NAME, LAST_SLEEP_CYCLE_ATTRIBUTE_NAME, TIMEZONE_ID_ATTRIBUTE_NAME ); do { final QueryRequest queryRequest = new QueryRequest() .withTableName(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributeSet) .withLimit(100) .withExclusiveStartKey(lastEvaluatedKey); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); lastEvaluatedKey = queryResult.getLastEvaluatedKey(); final List<Map<String, AttributeValue>> items = queryResult.getItems(); for (final Map<String, AttributeValue> item : items) { final Optional<SmartAlarmHistory> smartAlarmHistoryOptional = smartAlarmHistoryFromAttributeValues(item); if(smartAlarmHistoryOptional.isPresent()){ history.add(smartAlarmHistoryOptional.get()); } } LOGGER.warn("Account get timezone failed, no data or aws error.", accountId); }while (lastEvaluatedKey != null); return history; }

Target:
public List<SmartAlarmHistory> getSmartAlarmHistoryByScheduleTime(final long accountId, final DateTime start, final DateTime end){ final Map<String, Condition> queryConditions = new HashMap<String, Condition>(); final double maxRateLimitSec = 100d; final Condition selectDateCondition = new Condition() .withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList(new AttributeValue().withS(start.toString(DATETIME_FORMAT)), new AttributeValue().withS(end.toString(DATETIME_FORMAT))); queryConditions.put(CURRENT_TIME_ATTRIBUTE_NAME, selectDateCondition); final Condition selectAccountIdCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(accountId))); queryConditions.put(ACCOUNT_ID_ATTRIBUTE_NAME, selectAccountIdCondition); Map<String, AttributeValue> lastEvaluatedKey = null; final List<SmartAlarmHistory> history = new ArrayList<>(); final Collection<String> targetAttributeSet = new HashSet<String>(); Collections.addAll(targetAttributeSet, ACCOUNT_ID_ATTRIBUTE_NAME, CURRENT_TIME_ATTRIBUTE_NAME, EXPECTED_RING_TIME_ATTRIBUTE_NAME, SMART_RING_TIME_ATTRIBUTE_NAME, LAST_SLEEP_CYCLE_ATTRIBUTE_NAME, TIMEZONE_ID_ATTRIBUTE_NAME ); final RateLimiter rateLimiter = RateLimiter.create(maxRateLimitSec); do { rateLimiter.acquire(); final QueryRequest queryRequest = new QueryRequest() .withTableName(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributeSet) .withLimit(100) .withExclusiveStartKey(lastEvaluatedKey); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); lastEvaluatedKey = queryResult.getLastEvaluatedKey(); final List<Map<String, AttributeValue>> items = queryResult.getItems(); for (final Map<String, AttributeValue> item : items) { final Optional<SmartAlarmHistory> smartAlarmHistoryOptional = smartAlarmHistoryFromAttributeValues(item); if(smartAlarmHistoryOptional.isPresent()){ history.add(smartAlarmHistoryOptional.get()); } } LOGGER.warn("Account get timezone failed, no data or aws error.", accountId); }while (lastEvaluatedKey != null); return history; }