-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
refactor(biz): 修改提交查询逻辑以使用ID替代时间戳 #5584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,5 @@ target | |
| *.orig | ||
| .flattened-pom.xml | ||
|
|
||
| .gradle/* | ||
| .vscode/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,10 +30,7 @@ | |
| import com.ctrip.framework.apollo.common.entity.AppNamespace; | ||
|
|
||
| import com.ctrip.framework.apollo.common.exception.ServiceException; | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Arrays; | ||
| import java.util.Date; | ||
| import java.util.HashSet; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
@@ -124,28 +121,24 @@ public void testDeleteNamespace() { | |
| @Test | ||
| @Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
| @Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
| public void testGetCommitsByModifiedTime() throws ParseException { | ||
| String format = "yyyy-MM-dd HH:mm:ss"; | ||
| SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); | ||
|
|
||
| Date lastModifiedTime = simpleDateFormat.parse("2020-08-22 09:00:00"); | ||
|
|
||
| List<Commit> commitsByDate = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, lastModifiedTime, null); | ||
|
|
||
| Date lastModifiedTimeGreater = simpleDateFormat.parse("2020-08-22 11:00:00"); | ||
| List<Commit> commitsByDateGreater = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, lastModifiedTimeGreater, null); | ||
|
|
||
|
|
||
| Date lastModifiedTimePage = simpleDateFormat.parse("2020-08-22 09:30:00"); | ||
| List<Commit> commitsByDatePage = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, lastModifiedTimePage, PageRequest.of(0, 1)); | ||
|
|
||
| assertEquals(1, commitsByDate.size()); | ||
| assertEquals(0, commitsByDateGreater.size()); | ||
| assertEquals(1, commitsByDatePage.size()); | ||
|
|
||
| public void testGetCommitsByModifiedTime() { | ||
| // namespace-test.sql has 1 commit for (commitTestApp, default, application) | ||
| // find(..., id, page) returns commits with id >= given id for the namespace | ||
| List<Commit> allCommits = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, PageRequest.of(0, 10)); | ||
| assertEquals(1, allCommits.size()); | ||
| Long commitId = allCommits.get(0).getId(); | ||
|
|
||
| List<Commit> commitsById = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, commitId, null); | ||
| List<Commit> commitsByIdGreater = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, commitId + 1, null); | ||
| List<Commit> commitsByIdPage = commitService.find(commitTestApp, testCluster, | ||
| testPrivateNamespace, commitId, PageRequest.of(0, 1)); | ||
|
|
||
| assertEquals(1, commitsById.size()); | ||
| assertEquals(0, commitsByIdGreater.size()); | ||
| assertEquals(1, commitsByIdPage.size()); | ||
|
Comment on lines
+124
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix Spotless formatting violations and rename test method.
As per coding guidelines, "Run 🧰 Tools🪛 GitHub Actions: code style check[error] 124-131: Spotless Java formatting check failed in spotless:2.43.0:check for project apollo-biz. The following files had format violations, including incorrect line breaks/indentation in List assignments (e.g., allCommits, commitsById, commitsByIdGreater). Run 'mvn spotless:apply' to fix. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: apolloconfig/apollo
Length of output: 1145
🏁 Script executed:
Repository: apolloconfig/apollo
Length of output: 84254
🏁 Script executed:
Repository: apolloconfig/apollo
Length of output: 5608
🏁 Script executed:
Repository: apolloconfig/apollo
Length of output: 1027
Critical: Cross-entity ID comparison produces incorrect results.
Release.idandCommit.idare generated from independent auto-increment sequences (both entities extendBaseEntitywhich usesGenerationType.IDENTITY). Filtering commits wherecommit.id >= release.idhas no meaningful correlation to the release timing.For example, if
Releasehas ID 5000 but relevantCommitrecords have IDs 100-200, this query will return zero results even though those commits occurred after the release.The original timestamp-based approach was semantically correct. To fix the performance issue, consider:
Commit.DataChange_LastTimeand keep the timestamp-based query, orlastCommitIdon Release at release time and filter using that), ordataChangeCreatedTime >= latestActiveRelease.getDataChangeCreatedTime(), then use that Commit ID for subsequent filtering.🤖 Prompt for AI Agents