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

add support for geoWithin.centerSphere queries via withJSON #4825

Merged
merged 6 commits into from
Jun 12, 2018
Merged

add support for geoWithin.centerSphere queries via withJSON #4825

merged 6 commits into from
Jun 12, 2018

Conversation

mtrezza
Copy link
Member

@mtrezza mtrezza commented Jun 11, 2018

This allows an unsorted geo query via withJSON as a faster performing alternative to the sorted geo queries of withinKilometers, withinMiles and withinRadius if sorting by distance is not needed.

@mtrezza
Copy link
Member Author

mtrezza commented Jun 11, 2018

As described in this issue #4824

@codecov
Copy link

codecov bot commented Jun 11, 2018

Codecov Report

Merging #4825 into master will increase coverage by <.01%.
The diff coverage is 98%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4825      +/-   ##
==========================================
+ Coverage   92.72%   92.73%   +<.01%     
==========================================
  Files         119      119              
  Lines        8688     8722      +34     
==========================================
+ Hits         8056     8088      +32     
- Misses        632      634       +2
Impacted Files Coverage Δ
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.2% <100%> (-0.05%) ⬇️
src/Adapters/Storage/Mongo/MongoTransform.js 87.12% <96.77%> (+0.29%) ⬆️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 260c466...c0f8770. Read the comment docs.

@dplewis
Copy link
Member

dplewis commented Jun 11, 2018

@mtrezza This was requested a while ago but never made it in.

#4060 You can use this as a reference.

@mtrezza
Copy link
Member Author

mtrezza commented Jun 11, 2018

@dplewis Can you please help me out on this one, Travis CI failed for postgres with:

Parse.Query testing toJSON works with geoWithin.centerSphere

  • Failed: Postgres doesn't support this query type yet {"$geoWithin":{"$centerSphere":[{"__type":"GeoPoint","latitude":0,"longitude":0},0.24642913200439492]}}

I think the $centerSphere query only makes sense for mongoDB as it is a different DB query with a performance advantage compared to $nearSphere.$maxDistance.

Now I added the logic to PostgresStorageAdapter.js but technically it is the same DB request as this existing one, just without the sorts line:

if (fieldValue.$nearSphere) {
const point = fieldValue.$nearSphere;
const distance = fieldValue.$maxDistance;
const distanceInKM = distance * 6371 * 1000;
patterns.push(`ST_distance_sphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2})::geometry) <= $${index + 3}`);
sorts.push(`ST_distance_sphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2})::geometry) ASC`)
values.push(fieldName, point.longitude, point.latitude, distanceInKM);
index += 4;

I saw that tests can be DB specific with it_only_db('mongo'). So should I keep the changes to PostgresStorageAdapter.js or make the test mongoDB specific?

@dplewis dplewis requested a review from flovilmart June 12, 2018 00:51
@flovilmart
Copy link
Contributor

I’ll review tomorrow first thing!

@mtrezza
Copy link
Member Author

mtrezza commented Jun 12, 2018

@flovilmart do you know why the coverage for meetup.js changed? I haven’t changed anything in the file or changed any existing tests.

@flovilmart
Copy link
Contributor

@mtrezza this are false positives

@mtrezza
Copy link
Member Author

mtrezza commented Jun 12, 2018

@flovilmart Can you give me a hint on how to make parse-server use my local clone of the JS SDK or vice-versa? Then I'll add the convenience functions like withinKilometersUnsorted to the JS SDK. In a new PR that is.

@flovilmart
Copy link
Contributor

You can use npm link to provide a temporary link between packages

https://docs.npmjs.com/cli/link

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

Looking good!

@flovilmart flovilmart merged commit 1e29d02 into parse-community:master Jun 12, 2018
@mtrezza mtrezza deleted the add_support_geoWithin_centerSphere branch June 12, 2018 22:25
@mtrezza mtrezza restored the add_support_geoWithin_centerSphere branch June 12, 2018 22:30
@mtrezza mtrezza deleted the add_support_geoWithin_centerSphere branch June 12, 2018 22:30
@dplewis dplewis mentioned this pull request Jun 14, 2018
8 tasks
flovilmart pushed a commit that referenced this pull request Aug 12, 2018
* add support for geoWithin.centerSphere queries via withJSON

* added test for passing array of lat, lng instead of Parse.GeoPoint

* added postgres support

* added more tests

* improved tests and validation

* added more tests
flovilmart pushed a commit that referenced this pull request Aug 12, 2018
* add support for geoWithin.centerSphere queries via withJSON

* added test for passing array of lat, lng instead of Parse.GeoPoint

* added postgres support

* added more tests

* improved tests and validation

* added more tests
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
…mmunity#4825)

* add support for geoWithin.centerSphere queries via withJSON

* added test for passing array of lat, lng instead of Parse.GeoPoint

* added postgres support

* added more tests

* improved tests and validation

* added more tests
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.

3 participants