-
Couldn't load subscription status.
- Fork 1
Tfh 0827 #404
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
base: review
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @tfhddd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request primarily focuses on enhancing the corporate signing management system by introducing pagination capabilities. This allows community managers to efficiently browse and retrieve corporate signing records in manageable chunks, improving performance and user experience when dealing with a large number of entries. Additionally, a minor update to the SMTP configuration has been included.
Highlights
- Pagination for Corporate Signings: Introduced new functionality to retrieve corporate signing records with pagination, allowing for efficient fetching of large datasets.
- New API Endpoint: Added a new GET API endpoint
/page/:link_idunderCorporationSigningControllerto expose the paginated corporate signing data. - MongoDB DAO Enhancements: Implemented new
GetDocsPageandGetDocsCountmethods in the MongoDB Data Access Object (DAO) to support paginated queries and total document counts. - SMTP Host Update: Updated the default SMTP host configuration from
smtp.exmail.qq.comtosmtp.qq.com.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review | Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary | Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help | Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request successfully adds pagination support for listing corporation signings. The changes span across the data, application, and controller layers, including a new API endpoint. The implementation is mostly solid. I've identified a few areas for improvement:
- API Documentation: The Swagger documentation for the new endpoint is incomplete and has an error.
- Code Style: There's some inconsistent naming for pagination parameters (
pagevsintPage) across different layers, and a case of variable shadowing. - Performance: The repository implementation for fetching paginated data makes two database calls, which could be optimized in the future.
My detailed comments provide specific suggestions to address these points.
| func (impl *daoImpl) GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error { | ||
| return impl.withContext(func(ctx context.Context) error { | ||
| // 构建查询选项 | ||
| opts := options.Find() | ||
| if len(project) > 0 { | ||
| opts.SetProjection(project) | ||
| } | ||
| opts.SetSkip(int64((intPage - 1) * intPageSize)) | ||
| opts.SetLimit(int64(intPageSize)) | ||
| // 执行查询 | ||
| cursor, err := impl.col.Find(ctx, filter, opts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return cursor.All(ctx, result) | ||
| }) | ||
| } |
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.
For consistency with other layers in the call stack, the parameter names should be page and pageSize instead of intPage and intPageSize. Remember to update their usage within the function body as well.
| func (impl *daoImpl) GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error { | |
| return impl.withContext(func(ctx context.Context) error { | |
| // 构建查询选项 | |
| opts := options.Find() | |
| if len(project) > 0 { | |
| opts.SetProjection(project) | |
| } | |
| opts.SetSkip(int64((intPage - 1) * intPageSize)) | |
| opts.SetLimit(int64(intPageSize)) | |
| // 执行查询 | |
| cursor, err := impl.col.Find(ctx, filter, opts) | |
| if err != nil { | |
| return err | |
| } | |
| return cursor.All(ctx, result) | |
| }) | |
| } | |
| func (impl *daoImpl) GetDocsPage(filter, project bson.M, page, pageSize int, result interface{}) error { | |
| return impl.withContext(func(ctx context.Context) error { | |
| // 构建查询选项 | |
| opts := options.Find() | |
| if len(project) > 0 { | |
| opts.SetProjection(project) | |
| } | |
| opts.SetSkip(int64((page - 1) * pageSize)) | |
| opts.SetLimit(int64(pageSize)) | |
| // 执行查询 | |
| cursor, err := impl.col.Find(ctx, filter, opts) | |
| if err != nil { | |
| return err | |
| } | |
| return cursor.All(ctx, result) | |
| }) | |
| } |
| err := impl.withContext(func(ctx context.Context) error { | ||
| var err error | ||
| count, err = impl.col.CountDocuments(ctx, filter) | ||
| return err | ||
| }) |
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 err variable is shadowed inside the closure. While this is not a bug, it makes the code harder to read and is generally discouraged in Go. You can refactor this to be more idiomatic and avoid shadowing by using a named return for the closure.
err := impl.withContext(func(ctx context.Context) (err error) { count, err = impl.col.CountDocuments(ctx, filter) return })| // @Param link_id path string true "link id" | ||
| // @Success 200 {object} models.CorporationSigningSummary |
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 Swagger documentation for this endpoint has a couple of issues:
- It's missing definitions for the
pageandpage_sizequery parameters. - The success response object is incorrect. It should be
models.CorporationSigningPageSummarywhich includes total count and data array.
| // @Param link_id path string true "link id" | |
| // @Success 200 {object} models.CorporationSigningSummary | |
| // @Param link_id path string true "link id" | |
| // @Param page query int false "page number" | |
| // @Param page_size query int false "page size" | |
| // @Success 200 {object} models.CorporationSigningPageSummary |
| Find(string) (domain.CorpSigning, error) | ||
| Remove(*domain.CorpSigning) error | ||
| FindAll(linkId string) ([]CorpSigningSummary, error) | ||
| FindPage(linkId string, intPage, intPageSize int) (CorpSigningSummaryPage, error) |
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 parameter names intPage and intPageSize are inconsistent with the naming used in other layers (e.g., page, pageSize in the application and adapter layers). For consistency across the codebase, it's better to use page and pageSize. This change should be propagated down to the repository implementation and DAO layers.
| FindPage(linkId string, intPage, intPageSize int) (CorpSigningSummaryPage, error) | |
| FindPage(linkId string, page, pageSize int) (CorpSigningSummaryPage, error) |
| func (impl *corpSigning) FindPage(linkId string, intPage, intPageSize int) (repository.CorpSigningSummaryPage, error) { | ||
| filter := linkIdFilter(linkId) | ||
| | ||
| project := bson.M{ | ||
| fieldDate: 1, | ||
| fieldCLAId: 1, | ||
| fieldLang: 1, | ||
| fieldRep: 1, | ||
| fieldCorp: 1, | ||
| fieldAdmin: 1, | ||
| fieldLinkId: 1, | ||
| fieldHasPDF: 1, | ||
| fieldCLANotify: 1, | ||
| } | ||
| | ||
| var docsPage repository.CorpSigningSummaryPage | ||
| docsPage.Total = 0 | ||
| total, err := impl.dao.GetDocsCount(filter) | ||
| if err != nil { | ||
| return docsPage, err | ||
| } | ||
| if total == 0 { | ||
| return docsPage, nil | ||
| } | ||
| | ||
| var dos []corpSigningDO | ||
| | ||
| if err := impl.dao.GetDocsPage(filter, project, intPage, intPageSize, &dos); err != nil { | ||
| return docsPage, err | ||
| } | ||
| | ||
| v := make([]repository.CorpSigningSummary, len(dos)) | ||
| for i := range dos { | ||
| v[i] = dos[i].toCorpSigningSummary() | ||
| } | ||
| docsPage.Data = v | ||
| docsPage.Total = total | ||
| return docsPage, nil | ||
| } |
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.
For consistency with other layers and the interface definition, the parameter names should be page and pageSize instead of intPage and intPageSize.
func (impl *corpSigning) FindPage(linkId string, page, pageSize int) (repository.CorpSigningSummaryPage, error) { filter := linkIdFilter(linkId) project := bson.M{ fieldDate: 1, fieldCLAId: 1, fieldLang: 1, fieldRep: 1, fieldCorp: 1, fieldAdmin: 1, fieldLinkId: 1, fieldHasPDF: 1, fieldCLANotify: 1, } var docsPage repository.CorpSigningSummaryPage docsPage.Total = 0 total, err := impl.dao.GetDocsCount(filter) if err != nil { return docsPage, err } if total == 0 { return docsPage, nil } var dos []corpSigningDO if err := impl.dao.GetDocsPage(filter, project, page, pageSize, &dos); err != nil { return docsPage, err } v := make([]repository.CorpSigningSummary, len(dos)) for i := range dos { v[i] = dos[i].toCorpSigningSummary() } docsPage.Data = v docsPage.Total = total return docsPage, nil }| total, err := impl.dao.GetDocsCount(filter) | ||
| if err != nil { | ||
| return docsPage, err | ||
| } | ||
| if total == 0 { | ||
| return docsPage, nil | ||
| } | ||
| | ||
| var dos []corpSigningDO | ||
| | ||
| if err := impl.dao.GetDocsPage(filter, project, intPage, intPageSize, &dos); err != nil { | ||
| return docsPage, err | ||
| } |
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.
This implementation makes two separate database calls: one to get the total count of documents and another to fetch the paginated data. While this is a common pattern, it can be inefficient under high load. For future optimization, consider using a single aggregation query with the $facet operator to retrieve both the count and the data in one round trip to the database. This would improve performance by reducing network latency and database load.
| GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error | ||
| GetDocsCount(filter bson.M) (int64, error) |
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.
For consistency, the parameter names should be page and pageSize instead of intPage and intPageSize.
| GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error | |
| GetDocsCount(filter bson.M) (int64, error) | |
| GetDocsPage(filter, project bson.M, page, pageSize int, result interface{}) error | |
| GetDocsCount(filter bson.M) (int64, error) |
No description provided.