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

Use ExtractParameters in handlers #2620

Merged
merged 51 commits into from
May 15, 2023

Conversation

w84thesun
Copy link
Contributor

@w84thesun w84thesun commented May 12, 2023

Description

Closes #2465.

In this PR I changed the delete, distinct, find, findAndModify, insert and update handlers to extract parameters with the ExtractParam function.

explain has to be implemented separately as its behaviour is slightly different from other handlers.

I added support for the following new tags:

  • positiveNumber - provided value must be of types [int, long, double] and greater than 0,
    double values would be rounded to long;
  • wholePositiveNumber - provided value must be of types [int, long] and greater than 0;
  • numericBool - provided value must be of types [bool, int, long, double] and would be converted to bool;
  • zeroOrOneAsBool - provided value must be of types [int, long, double] with possible values 0 or 1.

Please suggest better naming for numericBool and zeroOrOneAsBool.

Those are needed to choose from different numeric parameter functions like GetBoolOptionalParam or getWholeParamStrict. We can remove them if we will decide to unify the way we process parameters.

Some of the error messages were unified to form BSON <handler>.<parameter> has wrong ...

Readiness checklist

  • I added/updated unit tests.
  • I added/updated integration/compatibility tests.
  • I added/updated comments and checked rendering.
  • I made spot refactorings.
  • I updated user documentation.
  • I ran task all, and it passed.
  • I ensured that PR title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

@w84thesun w84thesun added the code/chore Code maintenance improvements label May 12, 2023
@w84thesun w84thesun self-assigned this May 12, 2023
@w84thesun w84thesun added the not ready Issues that are not ready to be worked on; PRs that should skip CI label May 12, 2023
@codecov
Copy link

codecov bot commented May 12, 2023

Codecov Report

Merging #2620 (c5ae8d5) into main (bab38ae) will decrease coverage by 37.56%.
The diff coverage is 48.01%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2620       +/-   ##
===========================================
- Coverage   66.24%   28.69%   -37.56%     
===========================================
  Files         419      419               
  Lines       20703    20444      -259     
===========================================
- Hits        13715     5866     -7849     
- Misses       6036    13985     +7949     
+ Partials      952      593      -359     
Impacted Files Coverage Δ
internal/handlers/common/count.go 0.00% <ø> (-100.00%) ⬇️
internal/handlers/common/delete.go 0.00% <0.00%> (-60.64%) ⬇️
internal/handlers/common/distinct.go 0.00% <0.00%> (-62.20%) ⬇️
internal/handlers/common/explain.go 0.00% <ø> (-69.12%) ⬇️
internal/handlers/common/find.go 0.00% <0.00%> (-65.52%) ⬇️
internal/handlers/common/findandmodify.go 0.00% <0.00%> (-87.20%) ⬇️
internal/handlers/common/insert.go 0.00% <0.00%> (-55.56%) ⬇️
internal/handlers/common/limit.go 0.00% <ø> (-60.87%) ⬇️
internal/handlers/common/params.go 3.87% <ø> (-89.62%) ⬇️
internal/handlers/common/update_params.go 0.00% <0.00%> (-59.04%) ⬇️
... and 9 more

... and 121 files with indirect coverage changes

Flag Coverage Δ
integration 5.43% <0.00%> (-53.77%) ⬇️
mongodb 5.43% <0.00%> (+0.06%) ⬆️
pg ?
unit 27.17% <48.01%> (+1.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@mergify
Copy link
Contributor

mergify bot commented May 13, 2023

@w84thesun this pull request has merge conflicts.

@mergify mergify bot added the conflict PRs that have merge conflicts label May 13, 2023
@w84thesun w84thesun enabled auto-merge (squash) May 13, 2023 15:23
@w84thesun w84thesun requested review from AlekSi, a team, rumyantseva and noisersup May 13, 2023 15:52
Copy link
Member

@chilagrow chilagrow left a comment

Choose a reason for hiding this comment

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

Great work 🤗 My comments are mainly just catching corner cases.

internal/handlers/common/delete.go Outdated Show resolved Hide resolved
internal/handlers/common/update_params.go Show resolved Hide resolved
internal/handlers/commonparams/params.go Outdated Show resolved Hide resolved
internal/handlers/common/distinct.go Show resolved Hide resolved
internal/handlers/commonparams/extract_params.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

Started reviewing (not a full review yet).

New tags seem useful!

Copy link
Contributor

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

Started reviewing (not a full review yet).

New tags seem useful!

Dmitry and others added 3 commits May 15, 2023 08:53
Co-authored-by: Chi Fujii <chi.fujii@ferretdb.io>
Copy link
Contributor

@rumyantseva rumyantseva left a comment

Choose a reason for hiding this comment

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

Ok, I like the tests, and the returned errors look reasonable to me.
I see a bit of inconsistency in function names, but I think we can fix them later when we meet this inconsistency somewhere.

Copy link
Member

@chilagrow chilagrow left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@w84thesun w84thesun merged commit 87b0a6e into FerretDB:main May 15, 2023
@w84thesun w84thesun deleted the issue-2465-use-extract-parameters branch May 15, 2023 09:20
@AlekSi AlekSi added this to the Next milestone May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Refactor how we process handlers params
4 participants