Skip to content
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

GO-3870: HistoryGetVersions ignore limit param #1463

Merged

Conversation

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Copy link

coderabbitai bot commented Aug 9, 2024

Walkthrough

The recent changes improve the Versions method in the history struct by adding robust checks for empty data and limiting the number of returned versions. A new test function enhances coverage by validating different scenarios, ensuring the functionality behaves as expected under various conditions. These modifications improve error handling and maintain control over output size, ultimately refining the method's performance and reliability.

Changes

File Change Summary
core/history/history.go Enhanced Versions method with checks for empty data and limitations on returned versions.
core/history/history_test.go Added TestHistory_Versions function with multiple sub-tests to validate the Versions method. Cleaned up commented-out code.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HistoryService
    participant DataStore

    Client->>HistoryService: Request versions
    HistoryService->>DataStore: Fetch versions
    alt Data is not empty
        DataStore-->>HistoryService: Return versions
        HistoryService->>HistoryService: Check limit
        HistoryService->>Client: Return limited versions
    else Data is empty
        HistoryService-->>Client: Return empty response
    end
Loading

Poem

🐇 In the meadow where data flows,
A method now robustly grows.
With limits set and checks in place,
The versions dance, a graceful pace.
Happy tests, they hop and play,
Ensuring all works day by day! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Aug 9, 2024

Previous Coverage 47.0% of statements
New Coverage 47.1% of statements
Patch Coverage 100.0% of changed statements (4/4)

Coverage provided by /~https://github.com/seriousben/go-patch-cover-action

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b4f9c5 and 9e03646.

Files selected for processing (2)
  • core/history/history.go (3 hunks)
  • core/history/history_test.go (2 hunks)
Additional comments not posted (2)
core/history/history.go (1)

151-153: Improve handling of empty data slices.

The added check for empty data slices prevents unnecessary operations. This is a good enhancement for robustness.

core/history/history_test.go (1)

967-992: Test case aligns with PR objectives.

The test case "no changes" correctly validates the behavior when there are no changes, aligning with the PR objectives.

Comment on lines +180 to +182
if len(resp) > limit {
resp = resp[:limit]
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure limit parameter is correctly ignored.

The code truncates the resp slice if its length exceeds the specified limit. This contradicts the PR objective of ignoring the limit parameter. Consider removing this logic to align with the PR objectives.

-  if len(resp) > limit {
-    resp = resp[:limit]
-  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if len(resp) > limit {
resp = resp[:limit]
}

Comment on lines +861 to +915
t.Run("limit 10 - 10 changes", func(t *testing.T) {
// given
objectId := "objectId"
spaceID := "spaceID"
versionId := "versionId"

accountKeys, _ := accountdata.NewRandom()
account := accountKeys.SignKey.GetPublic()

blDataviewId := "blDataviewId"
relationKey := "key"

viewId := "viewId"
viewName := "view"

viewId1 := "viewId1"
view1Name := "view1"

viewId2 := "viewId2"
view2Name := "view2"

blDataview := provideDataviewBlock(viewId1, view1Name, relationKey, blDataviewId)

blSmartBlock := &model.Block{Id: objectId, Content: &model.BlockContentOfSmartblock{Smartblock: &model.BlockContentSmartblock{}}}

currChange := []*objecttree.Change{
// create block changes
provideBlockEmptyChange(objectId, account),
provideBlockCreateChange(blSmartBlock, account),
provideBlockCreateChange(blDataview, account),

// dataview changes
provideBlockDataviewViewSetChange(blDataviewId, viewId1, view1Name, relationKey, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId2, view2Name, relationKey, account),
provideBlockDataviewSourceSetChange(blDataviewId, account),
provideBlockDataviewRelationSetChange(blDataviewId, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId, viewName, relationKey, account),
provideBlockDataviewViewOrderChange(blDataviewId, viewId, viewId1, account),
provideBlockDataviewViewDeleteChange(blDataviewId, viewId2, account),
provideBlockDataviewRelationDeleteChange(blDataviewId, relationKey, account),
provideBlockDataviewObjectOrderChange(blDataviewId, viewId, account),
provideBlockDataviewGroupOrderChange(blDataviewId, viewId, account),
provideBlockDataviewViewUpdateChange(blDataviewId, viewId, account),
provideBlockDataviewTargetObjectChange(blDataviewId, account),
}

history := newFixture(t, currChange, objectId, spaceID, versionId)

// when
resp, err := history.Versions(domain.FullID{ObjectID: objectId, SpaceID: spaceID}, versionId, 10)

// then
assert.Nil(t, err)
assert.Len(t, resp, 10)
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case contradicts PR objectives.

The test case "limit 10 - 10 changes" validates the behavior of the limit parameter, which contradicts the PR objective of ignoring it. Consider revising this test case to align with the PR objectives.

-  t.Run("limit 10 - 10 changes", func(t *testing.T) {
+  t.Run("ignore limit parameter", func(t *testing.T) {

Committable suggestion was skipped due to low confidence.

Comment on lines +916 to +966
t.Run("number of changes equals limit", func(t *testing.T) {
// given
objectId := "objectId"
spaceID := "spaceID"
versionId := "versionId"

accountKeys, _ := accountdata.NewRandom()
account := accountKeys.SignKey.GetPublic()

blDataviewId := "blDataviewId"
relationKey := "key"

viewId := "viewId"
viewName := "view"

viewId1 := "viewId1"
view1Name := "view1"

viewId2 := "viewId2"
view2Name := "view2"

blDataview := provideDataviewBlock(viewId1, view1Name, relationKey, blDataviewId)

blSmartBlock := &model.Block{Id: objectId, Content: &model.BlockContentOfSmartblock{Smartblock: &model.BlockContentSmartblock{}}}

currChange := []*objecttree.Change{
// create block changes
provideBlockEmptyChange(objectId, account),
provideBlockCreateChange(blSmartBlock, account),
provideBlockCreateChange(blDataview, account),

// dataview changes
provideBlockDataviewViewSetChange(blDataviewId, viewId1, view1Name, relationKey, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId2, view2Name, relationKey, account),
provideBlockDataviewSourceSetChange(blDataviewId, account),
provideBlockDataviewRelationSetChange(blDataviewId, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId, viewName, relationKey, account),
provideBlockDataviewViewOrderChange(blDataviewId, viewId, viewId1, account),
provideBlockDataviewViewDeleteChange(blDataviewId, viewId2, account),
provideBlockDataviewRelationDeleteChange(blDataviewId, relationKey, account),
}

history := newFixture(t, currChange, objectId, spaceID, versionId)

// when
resp, err := history.Versions(domain.FullID{ObjectID: objectId, SpaceID: spaceID}, versionId, 10)

// then
assert.Nil(t, err)
assert.Len(t, resp, 10)
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case contradicts PR objectives.

The test case "number of changes equals limit" validates the behavior of the limit parameter, which contradicts the PR objective of ignoring it. Consider revising this test case to align with the PR objectives.

-  t.Run("number of changes equals limit", func(t *testing.T) {
+  t.Run("ignore limit parameter", func(t *testing.T) {

Committable suggestion was skipped due to low confidence.

Comment on lines +805 to +860
func TestHistory_Versions(t *testing.T) {
t.Run("limit 0 - 100 changes", func(t *testing.T) {
// given
objectId := "objectId"
spaceID := "spaceID"
versionId := "versionId"

accountKeys, _ := accountdata.NewRandom()
account := accountKeys.SignKey.GetPublic()

blDataviewId := "blDataviewId"
relationKey := "key"

viewId := "viewId"
viewName := "view"

viewId1 := "viewId1"
view1Name := "view1"

viewId2 := "viewId2"
view2Name := "view2"

blDataview := provideDataviewBlock(viewId1, view1Name, relationKey, blDataviewId)

blSmartBlock := &model.Block{Id: objectId, Content: &model.BlockContentOfSmartblock{Smartblock: &model.BlockContentSmartblock{}}}

currChange := []*objecttree.Change{
// create block changes
provideBlockEmptyChange(objectId, account),
provideBlockCreateChange(blSmartBlock, account),
provideBlockCreateChange(blDataview, account),

// dataview changes
provideBlockDataviewViewSetChange(blDataviewId, viewId1, view1Name, relationKey, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId2, view2Name, relationKey, account),
provideBlockDataviewSourceSetChange(blDataviewId, account),
provideBlockDataviewRelationSetChange(blDataviewId, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId, viewName, relationKey, account),
provideBlockDataviewViewOrderChange(blDataviewId, viewId, viewId1, account),
provideBlockDataviewViewDeleteChange(blDataviewId, viewId2, account),
provideBlockDataviewRelationDeleteChange(blDataviewId, relationKey, account),
provideBlockDataviewObjectOrderChange(blDataviewId, viewId, account),
provideBlockDataviewGroupOrderChange(blDataviewId, viewId, account),
provideBlockDataviewViewUpdateChange(blDataviewId, viewId, account),
provideBlockDataviewTargetObjectChange(blDataviewId, account),
}

history := newFixture(t, currChange, objectId, spaceID, versionId)

// when
resp, err := history.Versions(domain.FullID{ObjectID: objectId, SpaceID: spaceID}, versionId, 0)

// then
assert.Nil(t, err)
assert.Len(t, resp, 14)
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case contradicts PR objectives.

The test case "limit 0 - 100 changes" validates the behavior of the limit parameter, which contradicts the PR objective of ignoring it. Consider revising this test case to align with the PR objectives.

-  t.Run("limit 0 - 100 changes", func(t *testing.T) {
+  t.Run("ignore limit parameter", func(t *testing.T) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func TestHistory_Versions(t *testing.T) {
t.Run("limit 0 - 100 changes", func(t *testing.T) {
// given
objectId := "objectId"
spaceID := "spaceID"
versionId := "versionId"
accountKeys, _ := accountdata.NewRandom()
account := accountKeys.SignKey.GetPublic()
blDataviewId := "blDataviewId"
relationKey := "key"
viewId := "viewId"
viewName := "view"
viewId1 := "viewId1"
view1Name := "view1"
viewId2 := "viewId2"
view2Name := "view2"
blDataview := provideDataviewBlock(viewId1, view1Name, relationKey, blDataviewId)
blSmartBlock := &model.Block{Id: objectId, Content: &model.BlockContentOfSmartblock{Smartblock: &model.BlockContentSmartblock{}}}
currChange := []*objecttree.Change{
// create block changes
provideBlockEmptyChange(objectId, account),
provideBlockCreateChange(blSmartBlock, account),
provideBlockCreateChange(blDataview, account),
// dataview changes
provideBlockDataviewViewSetChange(blDataviewId, viewId1, view1Name, relationKey, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId2, view2Name, relationKey, account),
provideBlockDataviewSourceSetChange(blDataviewId, account),
provideBlockDataviewRelationSetChange(blDataviewId, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId, viewName, relationKey, account),
provideBlockDataviewViewOrderChange(blDataviewId, viewId, viewId1, account),
provideBlockDataviewViewDeleteChange(blDataviewId, viewId2, account),
provideBlockDataviewRelationDeleteChange(blDataviewId, relationKey, account),
provideBlockDataviewObjectOrderChange(blDataviewId, viewId, account),
provideBlockDataviewGroupOrderChange(blDataviewId, viewId, account),
provideBlockDataviewViewUpdateChange(blDataviewId, viewId, account),
provideBlockDataviewTargetObjectChange(blDataviewId, account),
}
history := newFixture(t, currChange, objectId, spaceID, versionId)
// when
resp, err := history.Versions(domain.FullID{ObjectID: objectId, SpaceID: spaceID}, versionId, 0)
// then
assert.Nil(t, err)
assert.Len(t, resp, 14)
})
func TestHistory_Versions(t *testing.T) {
t.Run("ignore limit parameter", func(t *testing.T) {
// given
objectId := "objectId"
spaceID := "spaceID"
versionId := "versionId"
accountKeys, _ := accountdata.NewRandom()
account := accountKeys.SignKey.GetPublic()
blDataviewId := "blDataviewId"
relationKey := "key"
viewId := "viewId"
viewName := "view"
viewId1 := "viewId1"
view1Name := "view1"
viewId2 := "viewId2"
view2Name := "view2"
blDataview := provideDataviewBlock(viewId1, view1Name, relationKey, blDataviewId)
blSmartBlock := &model.Block{Id: objectId, Content: &model.BlockContentOfSmartblock{Smartblock: &model.BlockContentSmartblock{}}}
currChange := []*objecttree.Change{
// create block changes
provideBlockEmptyChange(objectId, account),
provideBlockCreateChange(blSmartBlock, account),
provideBlockCreateChange(blDataview, account),
// dataview changes
provideBlockDataviewViewSetChange(blDataviewId, viewId1, view1Name, relationKey, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId2, view2Name, relationKey, account),
provideBlockDataviewSourceSetChange(blDataviewId, account),
provideBlockDataviewRelationSetChange(blDataviewId, account),
provideBlockDataviewViewSetChange(blDataviewId, viewId, viewName, relationKey, account),
provideBlockDataviewViewOrderChange(blDataviewId, viewId, viewId1, account),
provideBlockDataviewViewDeleteChange(blDataviewId, viewId2, account),
provideBlockDataviewRelationDeleteChange(blDataviewId, relationKey, account),
provideBlockDataviewObjectOrderChange(blDataviewId, viewId, account),
provideBlockDataviewGroupOrderChange(blDataviewId, viewId, account),
provideBlockDataviewViewUpdateChange(blDataviewId, viewId, account),
provideBlockDataviewTargetObjectChange(blDataviewId, account),
}
history := newFixture(t, currChange, objectId, spaceID, versionId)
// when
resp, err := history.Versions(domain.FullID{ObjectID: objectId, SpaceID: spaceID}, versionId, 0)
// then
assert.Nil(t, err)
assert.Len(t, resp, 14)
})

@@ -148,6 +148,9 @@ func (h *history) Versions(id domain.FullID, lastVersionId string, limit int) (r
if e != nil {
return nil, e
}
if len(data) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it possible that data == 0? Because I guess we will always call func on first element

@AnastasiaShemyakinskaya AnastasiaShemyakinskaya merged commit 3f5277b into main Aug 13, 2024
5 checks passed
@AnastasiaShemyakinskaya AnastasiaShemyakinskaya deleted the go-3870-historygetversions-ignore-limit-param branch August 13, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants