-
Notifications
You must be signed in to change notification settings - Fork 54
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-3273: fix history protocol and implementation #1482
GO-3273: fix history protocol and implementation #1482
Conversation
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
WalkthroughThe recent changes streamline the import functionality and enhance versioning management across multiple components. Key modifications include simplifying method signatures by removing unnecessary parameters, which improves code clarity and usability. Additionally, enhancements to the history structure allow for better handling of concurrent changes, ensuring robust version tracking and management within the system. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Service
participant Importer
participant History
User->>Service: Request to import changes
Service->>Importer: Call Import("")
Importer-->>Service: Return success
Service->>History: Update versioning
History-->>Service: Version updated
Service-->>User: Import successful
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 4
Outside diff range, codebase verification and nitpick comments (4)
core/history/history.go (2)
43-43
: Initializeheads
map with a capacity.Initializing the
heads
map with a non-zero capacity can improve performance if the expected number of entries is known.- return &history{heads: make(map[string]string, 0)} + return &history{heads: make(map[string]string)}
135-135
: Clarify the purpose ofcurHeads
.The
curHeads
map is used to manage current heads during versioning. Consider adding a comment to clarify its role for future maintainability.// curHeads tracks current heads during version iteration
core/history/history_test.go (2)
1118-1118
: Initializeheads
map with capacity innewFixture
.Consider initializing the
heads
map with a capacity if the expected size is known, for performance optimization.- heads: map[string]string{}, + heads: make(map[string]string),
1144-1144
: Initializeheads
map with capacity innewFixtureDiffVersions
.As with
newFixture
, consider initializing theheads
map with a capacity if the expected size is known.- heads: map[string]string{}, + heads: make(map[string]string),
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- cmd/debugtree/debugtree.go (2 hunks)
- core/block/editor/state/test/buildfast_test.go (2 hunks)
- core/debug/service.go (1 hunks)
- core/debug/treearchive/treeimporter.go (2 hunks)
- core/history/history.go (7 hunks)
- core/history/history_test.go (4 hunks)
Additional context used
GitHub Check: unit-test
core/debug/treearchive/treeimporter.go
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParamscore/history/history.go
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts
GitHub Check: lint
core/debug/treearchive/treeimporter.go
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams (typecheck)
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams) (typecheck)core/history/history.go
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts (typecheck)
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts) (typecheck)
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts) (typecheck)
Additional comments not posted (7)
core/block/editor/state/test/buildfast_test.go (1)
53-53
: LGTM! Verify test coverage.The removal of the boolean parameter from the
Import
method calls simplifies the code. Ensure that the test coverage remains adequate and that the change aligns with the expected behavior of theImport
method.Also applies to: 67-67
core/debug/treearchive/treeimporter.go (1)
47-47
: Simplification ofImport
method signature.The
Import
method signature has been simplified by removing the boolean parameter. This change reduces complexity and focuses the method on thebeforeId
parameter, which is beneficial for maintainability.cmd/debugtree/debugtree.go (1)
54-54
: LGTM! Verify import logic.The removal of the dereferenced
fromRoot
parameter simplifies the import calls. Ensure that this change aligns with the intended functionality and does not impact the import process.Also applies to: 85-85
core/debug/service.go (1)
190-190
: Verify the impact of using default options inBuildHistoryTree
.The change from
HistoryTreeOpts{BuildFullTree: true}
toHistoryTreeOpts{}
may alter the tree-building behavior. Ensure that the default options align with the intended functionality.core/history/history.go (2)
5-8
: Remove unused imports if not required.The imports
crypto/md5
,fmt
, andstrings
are necessary for the changes, but ensure thatslices
is used somewhere in the file. If not, consider removing it.Verification successful
The
slices
import is used and necessary.The
slices
import is utilized in the filecore/history/history.go
with theslices.Contains
function. Therefore, it should not be removed.
- Instances of usage:
if !slices.Contains(bundle.LocalAndDerivedRelationKeys, key)
if !slices.Contains(bundle.LocalAndDerivedRelationKeys, link.Key)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if `slices` is used in the codebase. # Test: Search for `slices` usage in the current file. rg --type go 'slices' core/history/history.goLength of output: 190
185-190
: EnsureretrieveHeads
handles missing entries gracefully.The
retrieveHeads
function defaults to returning theversionId
if not found. Verify that this behavior is appropriate for all use cases.Verification successful
The default behavior of
retrieveHeads
is appropriate for its usage.The function
retrieveHeads
is used in a context where it provides input to a history tree-building process. The code handles both single and multiple head scenarios, suggesting that the default behavior of returning theversionId
when no heads are found is suitable for its intended use.
core/history/history.go
: The function is used to supply heads toBuildHistoryTree
, which likely supports both single and multiple heads.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage and handling of `retrieveHeads` in the codebase. # Test: Search for `retrieveHeads` to ensure it is used correctly. rg --type go 'retrieveHeads'Length of output: 174
Script:
#!/bin/bash # Extract context around the usage of `retrieveHeads` in `core/history/history.go` rg --type go -A 10 'heads := h.retrieveHeads(versionId)' core/history/history.goLength of output: 82
Script:
#!/bin/bash # Extract more context around the usage of `retrieveHeads` in `core/history/history.go` rg --type go -A 20 'heads := h.retrieveHeads(versionId)' core/history/history.goLength of output: 82
Script:
#!/bin/bash # Search for the definition and usage of `retrieveHeads` in `core/history/history.go` to manually verify the context. rg --type go -A 20 'retrieveHeads' core/history/history.goLength of output: 1290
core/history/history_test.go (1)
993-1097
: Ensure comprehensive coverage for parallel editing.The test case "changes from parallel editing" effectively simulates concurrent changes. Ensure that all edge cases, such as conflicts and merges, are covered.
func (t *treeImporter) Import(beforeId string) (err error) { | ||
aclList, err := list.BuildAclList(t.listStorage, list.NoOpAcceptorVerifier{}) | ||
if err != nil { | ||
return | ||
} | ||
t.objectTree, err = objecttree.BuildNonVerifiableHistoryTree(objecttree.HistoryTreeParams{ | ||
TreeStorage: t.treeStorage, | ||
AclList: aclList, | ||
BeforeId: beforeId, | ||
Heads: []string{beforeId}, |
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.
Fix the unknown field error in HistoryTreeParams
.
The Heads
field in the HistoryTreeParams
struct is causing an error because it is not recognized. Ensure that the struct definition includes this field or adjust the code to use the correct fields.
- Heads: []string{beforeId},
+ // Ensure the correct field is used in HistoryTreeParams
Committable suggestion was skipped due to low confidence.
Tools
GitHub Check: unit-test
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams
GitHub Check: lint
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams (typecheck)
[failure] 94-94:
unknown field Heads in struct literal of type objecttree.HistoryTreeParams) (typecheck)
core/history/history.go
Outdated
func (h *history) fillVersionData(change *objecttree.Change, curHeads map[string]struct{}, participantId string, data []*pb.RpcHistoryVersion) []*pb.RpcHistoryVersion { | ||
curHeads[change.Id] = struct{}{} | ||
for _, previousId := range change.PreviousIds { | ||
delete(curHeads, previousId) | ||
} | ||
version := &pb.RpcHistoryVersion{ | ||
Id: change.Id, | ||
PreviousIds: change.PreviousIds, | ||
AuthorId: participantId, | ||
Time: change.Timestamp, | ||
} | ||
if len(curHeads) > 1 { | ||
var combinedHeads string | ||
for head := range curHeads { | ||
combinedHeads += head + " " | ||
} | ||
combinedHeads = strings.TrimSpace(combinedHeads) | ||
hashSum := fmt.Sprintf("%x", md5.Sum([]byte(combinedHeads))) | ||
h.heads[hashSum] = combinedHeads | ||
version.Id = hashSum | ||
} | ||
return append(data, version) | ||
} |
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.
Optimize fillVersionData
for multiple heads.
The method concatenates heads and computes an MD5 hash. Consider using a more efficient way to handle multiple heads, such as sorting them before concatenation to ensure consistency.
+ // Sort heads before concatenation for consistency
sort.Strings(heads)
Committable suggestion was skipped due to low confidence.
func (h *history) treeWithId(id domain.FullID, versionId string, includeBeforeId bool) (ht objecttree.HistoryTree, sbt smartblock.SmartBlockType, err error) { | ||
heads := h.retrieveHeads(versionId) | ||
spc, err := h.spaceService.Get(context.Background(), id.SpaceID) | ||
if err != nil { | ||
return | ||
} | ||
ht, err = spc.TreeBuilder().BuildHistoryTree(context.Background(), id.ObjectID, objecttreebuilder.HistoryTreeOpts{ | ||
BeforeId: beforeId, | ||
Include: includeBeforeId, | ||
Heads: heads, | ||
Include: includeBeforeId, |
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.
Address unknown field Heads
in BuildHistoryTree
.
The static analysis tool reports an unknown field Heads
in objecttreebuilder.HistoryTreeOpts
. Verify the struct definition and update the code accordingly.
- Heads: heads,
+ // Verify the correct field name or update struct definition
Committable suggestion was skipped due to low confidence.
Tools
GitHub Check: unit-test
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts
GitHub Check: lint
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts (typecheck)
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts) (typecheck)
[failure] 498-498:
unknown field Heads in struct literal of type objecttreebuilder.HistoryTreeOpts) (typecheck)
Heads: []string{currVersionId}, | ||
Include: true, |
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.
Address unknown field Heads
in BuildHistoryTree
call.
The static analysis tool reports an unknown field Heads
. Verify the struct definition in objecttreebuilder.HistoryTreeOpts
and update the test setup accordingly.
- Heads: []string{currVersionId},
+ // Verify the correct field name or update struct definition
Committable suggestion was skipped due to low confidence.
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
Coverage provided by /~https://github.com/seriousben/go-patch-cover-action |
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
…o-3273-fix-history-protocol-and-implementation # Conflicts: # go.mod # go.sum
Algorithm description https://linear.app/anytype/issue/GO-3273/fix-history-protocol-and-implementation