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

Fix where in array + dynamic limit and offset #171

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

exAspArk
Copy link
Contributor

Fixes #170

@coveralls
Copy link

coveralls commented Jan 17, 2019

Pull Request Test Coverage Report for Build 328

  • 14 of 15 (93.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.1%) to 87.397%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/mongo_ecto/normalized_query.ex 14 15 93.33%
Totals Coverage Status
Change from base Build 324: 1.1%
Covered Lines: 319
Relevant Lines: 365

💛 - Coveralls

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 1 possible new issue (including those that may have been commented here).

You can see more details about this review at https://ebertapp.io/github/ankhers/mongodb_ecto/pulls/171.

defp where_params_range({:not, _, [expr]}), do: where_params_range(expr)

defp where_params_range({_, _, exprs}) do
ranges = Enum.map(exprs, &where_params_range(&1)) |> Enum.filter(& &1)

Choose a reason for hiding this comment

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

Use a function call when a pipeline is only one function long

@exAspArk
Copy link
Contributor Author

exAspArk commented Jan 18, 2019

OK, I'm at a point when I think that it all works incorrectly 😭 I wrote a more complicated test case and tried to make it work:

https://github.com/ankhers/mongodb_ecto/blob/2d195a33e4c2519b51ba37d003e836a72a880194/test/mongo_ecto_test.exs#L94-L113

It uses these params:

{
  3, # visits
  4, 5, # not in visits
  #BSON.ObjectId<5c4218d5ac013d8d6e5ecadc>, #BSON.ObjectId<5c4218d5ac013d8d6e5ecadd>, #BSON.ObjectId<5c4218d5ac013d8d6e5ecade>, # in ids
  1, # offset
  2 # limit
}
# ^ it could be much more simple it lists were not "flattened"

but generates this expression:

{:and, [],
     [
       {:and, [],
        [
          {:==, [],
           [{{:., [], [{:&, [], [0]}, :visits]}, [], []}, {:^, [], [0]}]},
          {:not, [],
           [
             {:in, [],
              [{{:., [], [{:&, [], [0]}, :visits]}, [], []}, {:^, [], [1, 2]}]}
           ]}
        ]},
       {:in, [], [{{:., [], [{:&, [], [0]}, :id]}, [], []}, {:^, [], [2, 3]}]}
       # ^ why it starts with 2 for a list of [#BSON.ObjectId, #BSON.ObjectId, #BSON.ObjectId]
     ]}

@exAspArk
Copy link
Contributor Author

cc @ankhers @michalmuskala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants