-
Notifications
You must be signed in to change notification settings - Fork 47
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-3453: progress bars protocol #1274
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
WalkthroughThe changes primarily involve refactoring how progress messages are handled across various processes such as file downloads, imports, and exports. The Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant Client
participant Server
participant ProcessService
Client->>Server: ProcessSubscribe(Request)
Server->>ProcessService: Subscribe(token)
ProcessService->>Server: Subscribe(Response)
Server->>Client: ProcessSubscribe(Response)
Client->>Server: ProcessUnsubscribe(Request)
Server->>ProcessService: Unsubscribe(token)
ProcessService->>Server: Unsubscribe(Response)
Server->>Client: ProcessUnsubscribe(Response)
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 Configration 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: 5
Outside diff range and nitpick comments (3)
core/block/process/queue.go (1)
189-189
: The update to theInfo
method to use the newMessage
field aligns with the refactoring of process message handling. Consider adding a comment to clarify the purpose and expected content of theMessage
field for future maintainers.core/block/editor/file/file.go (1)
382-382
: The update to theInfo
method to use the newMessage
field aligns with the refactoring of process message handling. Consider adding a comment to clarify the purpose and expected content of theMessage
field for future maintainers.pb/protos/service/service.proto (1)
295-296
: Ensure the new RPC methodsProcessSubscribe
andProcessUnsubscribe
are properly documented.Adding comments to describe the purpose and usage of these new RPC methods would improve maintainability and clarity for other developers.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (6)
clientlibrary/service/service.pb.go
is excluded by!**/*.pb.go
,!**/*.pb.go
core/event/mock_event/mock_Sender.go
is excluded by!**/mock_*.go
docs/proto.md
is excluded by!**/proto.md
pb/commands.pb.go
is excluded by!**/*.pb.go
,!**/*.pb.go
pb/events.pb.go
is excluded by!**/*.pb.go
,!**/*.pb.go
pb/service/service.pb.go
is excluded by!**/*.pb.go
,!**/*.pb.go
Files selected for processing (20)
- core/block/editor/file/file.go (1 hunks)
- core/block/export/export.go (1 hunks)
- core/block/files.go (1 hunks)
- core/block/import/csv/converter_test.go (18 hunks)
- core/block/import/html/converter_test.go (1 hunks)
- core/block/import/importer.go (2 hunks)
- core/block/import/notion/api/search/search_test.go (1 hunks)
- core/block/import/pb/converter_test.go (7 hunks)
- core/block/import/txt/converter_test.go (1 hunks)
- core/block/process/progress.go (3 hunks)
- core/block/process/queue.go (1 hunks)
- core/block/process/service.go (4 hunks)
- core/block/process/service_test.go (1 hunks)
- core/event/event.go (2 hunks)
- core/event/event_grpc.go (2 hunks)
- core/process.go (2 hunks)
- pb/protos/commands.proto (1 hunks)
- pb/protos/events.proto (1 hunks)
- pb/protos/service/service.proto (1 hunks)
- util/builtinobjects/builtinobjects.go (1 hunks)
Additional comments not posted (22)
core/event/event.go (1)
16-17
: The addition ofBroadcastExceptSessions
to theSender
interface enhances the flexibility of event broadcasting by allowing exceptions. Good design choice.core/block/import/txt/converter_test.go (1)
20-20
: Updated progress initialization to use&pb.ModelProcessMessageOfImport{}
aligns with the new protocol for process messages. This change enhances flexibility and maintainability.core/process.go (2)
30-42
: The implementation ofProcessSubscribe
is robust, handling context initialization, subscription logic, and error management effectively.
44-56
: The implementation ofProcessUnsubscribe
effectively manages the unsubscribe logic with proper error handling and context management.core/block/files.go (1)
29-29
: Updated progress initialization to&pb.ModelProcessMessageOfSaveFile{}
is consistent with the new protocol for process messages, enhancing flexibility and maintainability.core/block/process/service_test.go (2)
62-86
: TheTestService_Subscribe
function effectively tests the subscription logic, ensuring that tokens are managed correctly in thedisabledProcessEvent
map.
88-101
: TheTestService_Unsubscribe
function effectively tests the unsubscribe logic, ensuring that tokens are correctly added to thedisabledProcessEvent
map.core/block/process/progress.go (1)
25-30
: Refactoring of theNewProgress
function and theprogress
struct to use theprocessMessage
field aligns with the new protocol for process messages, enhancing flexibility and maintainability.Also applies to: 39-41, 137-137
core/block/process/service.go (1)
Line range hint
101-111
: The update to useBroadcastExceptSessions
in themonitor
method enhances the functionality by allowing selective broadcasting. Ensure that thegetExcludedSessions
method is thoroughly tested to handle concurrent modifications safely.core/block/import/html/converter_test.go (1)
32-32
: The update to useModelProcessMessageOfImport
in the test setup is consistent with the new progress message handling. Consider adding more test cases to cover different scenarios and error conditions.core/block/import/pb/converter_test.go (1)
46-46
: The update to useModelProcessMessageOfImport
in the test setup is consistent with the new progress message handling. Consider adding more test cases to cover different scenarios and error conditions.Also applies to: 66-66, 93-93, 111-111, 124-124, 144-144, 180-180
core/block/import/importer.go (2)
244-246
: The refactoring ofsetupProgressBar
to usepb.IsModelProcessMessage
aligns with the overall PR objectives to enhance flexibility in process message handling.
281-281
: The update inImportWeb
to use&pb.ModelProcessMessageOfImport{}
for progress initialization is consistent with the refactoring strategy outlined in the PR.core/block/import/notion/api/search/search_test.go (1)
35-35
: The update inTest_GetDatabaseSuccess
to use&pb.ModelProcessMessageOfImport{}
for progress initialization is consistent with the refactoring strategy outlined in the PR.util/builtinobjects/builtinobjects.go (1)
539-539
: LGTM! The update to use&pb.ModelProcessMessageOfImport{}
insetupProgress
aligns with the refactoring of process messages.core/block/import/csv/converter_test.go (1)
25-25
: LGTM! The updates to use&pb.ModelProcessMessageOfImport{}
in various test functions align with the refactoring of process messages.Also applies to: 50-50, 83-83, 112-112, 153-153, 172-172, 212-212, 240-240, 287-287, 342-342, 363-363, 384-384, 412-412, 458-458, 564-564, 606-606, 674-674, 712-712
core/block/export/export.go (5)
102-104
: Update to use newpb.ModelProcessMessageOfExport
for process message initialization.This change aligns with the PR's objective to refactor process message handling using the new protocol buffer definitions. It enhances type safety and clarity in the code.
102-104
: Refactored process message initialization inExport
method.The refactoring to use
pb.ModelProcessMessageOfExport
instead of a generic type or enum improves the clarity and type safety of the process message handling. This change is consistent with the overall PR objectives of enhancing the process message protocol.
102-104
: Concurrency handling inexportDocs
.The use of atomic operations for incrementing the success count and the structured handling of concurrent tasks ensure that the export process is both efficient and thread-safe. This is a good practice in handling concurrency in Go.
102-104
: Improved error handling insendNotification
.The method now appropriately determines the type of notification to send based on the presence of an error, which enhances the robustness and user-friendliness of the export functionality.
102-104
: Robust file cleanup incleanupFile
.The method ensures that files are properly closed and deleted if necessary, which prevents resource leakage and maintains the integrity of the file system during export operations.
pb/protos/events.proto (1)
1079-1093
: The addition of specific message types for process actions enhances the granularity and specificity of process handling.
pb/protos/commands.proto
Outdated
message Unsubscribe { | ||
message Request {} | ||
|
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.
Add documentation for the Unsubscribe
method.
Similar to the Subscribe
method, the Unsubscribe
method is missing documentation. Adding detailed comments will help developers understand the purpose and usage of this method more clearly.
pb/protos/commands.proto
Outdated
message Subscribe { | ||
message Request {} | ||
|
||
message Response { | ||
Error error = 1; | ||
|
||
message Error { | ||
Code code = 1; | ||
string description = 2; | ||
|
||
enum Code { | ||
NULL = 0; | ||
UNKNOWN_ERROR = 1; | ||
BAD_INPUT = 2; | ||
} | ||
} | ||
} | ||
} |
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.
Add documentation for the Subscribe
method.
The Subscribe
method lacks documentation. It's important to maintain comprehensive documentation, especially for public APIs, to ensure they are easily understandable and usable by developers. Consider adding a brief description of what the method does, its parameters, and what it returns.
// BroadcastExceptSessions broadcasts the event to session except provided | ||
func (es *GrpcSender) BroadcastExceptSessions(event *pb.Event, exceptTokens []string) { | ||
es.ServerMutex.RLock() | ||
defer es.ServerMutex.RUnlock() | ||
|
||
for _, s := range es.Servers { | ||
if !slices.Contains(exceptTokens, s.Token) { | ||
es.sendEvent(s, event) | ||
} | ||
} | ||
} |
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.
The implementation of BroadcastExceptSessions
method looks correct and thread-safe.
Would you like me to help create a unit test for this method to ensure it behaves as expected under various scenarios?
// Subscribe remove session from the map of disabled sessions | ||
Subscribe(token string) | ||
// Unsubscribe add session to the map of disabled sessions | ||
Unsubscribe(token string) |
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.
The implementation of Subscribe
and Unsubscribe
methods along with the getExcludedSessions
helper function is correct. However, consider adding more robust synchronization or using concurrent-safe data structures to manage the disabledProcessEvent
map to prevent potential race conditions.
- map[string]struct{}
+ sync.Map
Also applies to: 179-199
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.
// Subscribe remove session from the map of disabled sessions | |
Subscribe(token string) | |
// Unsubscribe add session to the map of disabled sessions | |
Unsubscribe(token string) | |
// Subscribe remove session from the map of disabled sessions | |
Subscribe(token string) | |
// Unsubscribe add session to the map of disabled sessions | |
Unsubscribe(token string) |
func (es *CallbackSender) BroadcastExceptSessions(event *pb.Event, exceptTokens []string) { | ||
es.callback(event) | ||
} |
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.
The implementation of BroadcastExceptSessions
should exclude the specified sessions. Currently, it broadcasts to all sessions.
- es.callback(event)
+ for _, session := range es.sessions {
+ if !contains(exceptTokens, session.token) {
+ es.callback(event)
+ }
+ }
Please ensure that sessions
and contains
logic is implemented to handle the exclusion properly.
Committable suggestion was skipped due low confidence.
Coverage provided by https://github.com/seriousben/go-patch-cover-action |
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
…o-3453-progress-bars-protocol # Conflicts: # clientlibrary/service/service.pb.go # pb/commands.pb.go # pb/service/service.pb.go
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
… github.com:anyproto/anytype-heart into go-3453-progress-bars-protocol
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
…o-3453-progress-bars-protocol # Conflicts: # clientlibrary/service/service.pb.go # core/block/import/csv/converter_test.go # pb/commands.pb.go # pb/service/service.pb.go
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
…o-3453-progress-bars-protocol # Conflicts: # pb/commands.pb.go
Signed-off-by: AnastasiaShemyakinskaya <[email protected]>
https://linear.app/anytype/issue/GO-3453/[next]-progress-bars-protocol