GODRIVER-3902 Move UpdateSearchIndex to the mongo package. - #2500
GODRIVER-3902 Move UpdateSearchIndex to the mongo package.#2500qingyang-hu wants to merge 3 commits into
Conversation
🧪 Performance ResultsCommit SHA: bfa3dedThe following benchmark tests for version 6a6770cc0d9c2c0007b0ddac had statistically significant changes (i.e., |z-score| > 1.96):
For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch. |
API Change Report./v2/x/mongo/driver/operationincompatible changesNewUpdateSearchIndex: removed |
There was a problem hiding this comment.
Pull request overview
This PR refactors the updateSearchIndex operation implementation by moving it out of x/mongo/driver/operation and into the public mongo package as an unexported operation type, simplifying the call site in SearchIndexView.UpdateOne.
Changes:
- Delete the exported
operation.UpdateSearchIndeximplementation (and its fluent setters/constructor) fromx/mongo/driver/operation. - Add an unexported
mongo.updateSearchIndexOpwith anexecutemethod to run the command viadriver.Operation. - Update
SearchIndexView.UpdateOneto construct and execute the new unexported op directly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| x/mongo/driver/operation/update_search_index.go | Removes the exported UpdateSearchIndex operation implementation from the operation package. |
| mongo/search_index_view.go | Switches UpdateOne to use the new in-package unexported operation struct instead of operation.NewUpdateSearchIndex(...). |
| mongo/op_update_search_index.go | Adds the unexported updateSearchIndexOp implementation inside the mongo package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var ok bool | ||
| usir.Ok, ok = element.Value().AsInt32OK() | ||
| if !ok { | ||
| return usir, fmt.Errorf("response field 'ok' is type int32, but received BSON type %s", element.Value().Type) |
| res updateSearchIndexResult | ||
| serverAPI *driver.ServerAPIOptions | ||
| timeout *time.Duration | ||
| } | ||
|
|
||
| // updateSearchIndexResult represents a single index in the updateSearchIndexResult result. | ||
| type updateSearchIndexResult struct { | ||
| Ok int32 | ||
| } | ||
|
|
||
| func buildUpdateSearchIndexResult(response bsoncore.Document) (updateSearchIndexResult, error) { | ||
| elements, err := response.Elements() | ||
| if err != nil { | ||
| return updateSearchIndexResult{}, err | ||
| } | ||
| usir := updateSearchIndexResult{} | ||
| for _, element := range elements { | ||
| if element.Key() == "ok" { | ||
| var ok bool | ||
| usir.Ok, ok = element.Value().AsInt32OK() | ||
| if !ok { | ||
| return usir, fmt.Errorf("response field 'ok' is type int32, but received BSON type %s", element.Value().Type) | ||
| } | ||
| } | ||
| } | ||
| return usir, nil | ||
| } | ||
|
|
||
| func (usi *updateSearchIndexOp) processResponse(_ context.Context, resp bsoncore.Document, _ driver.ResponseInfo) error { | ||
| var err error | ||
| usi.res, err = buildUpdateSearchIndexResult(resp) | ||
| return err |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GODRIVER-3902
Summary
UpdateSearchIndexfrom "x/mongo/driver/operation" into themongopackage as an unexportedupdateSearchIndexOp.NewUpdateSearchIndexconstructor are removed.NewUpdateSearchIndex, andResult()are dropped.Background & Motivation