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 invalid_reason call to check for polygon validity during job alerts #7391

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ RUN apt update -yq \
&& curl -sL https://deb.nodesource.com/setup_$NODEJS_MAJOR_VERSION.x | bash

# Set up dependencies
RUN apt update && apt install -y nodejs postgresql-client redis-tools less vim sudo shared-mime-info man-db libgeos-dev
RUN apt update && apt install -y nodejs postgresql-client redis-tools less vim sudo shared-mime-info man-db
RUN npm install -g yarn

# Install Terraform
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Install geos libraries
run: sudo apt install libgeos-dev

- name: Checkout code
uses: actions/checkout@v4

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
# Alpine v3.19.
# TODO: Regularly check in the alpine ruby "3.3.6-alpine3.19" images for its latest upgraded packages so we can remove
# the hardcoded versions below when they have been updated in the alpine ruby image.
ARG PROD_PACKAGES="imagemagick libpng libjpeg libxml2 libxslt libpq tzdata shared-mime-info postgresql15 busybox openssl geos-dev"
ARG PROD_PACKAGES="imagemagick libpng libjpeg libxml2 libxslt libpq tzdata shared-mime-info postgresql15 busybox openssl"

FROM ruby:3.3.6-alpine3.19 AS builder

11 changes: 2 additions & 9 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
@@ -86,20 +86,13 @@ def vacancies_matching(default_scope)

extend DistanceHelper

# 2D Cartesian factory backed by the GEOS C API (see https://github.com/rgeo/rgeo/blob/main/doc/Factory-Compatibility.md)
# we transform our polygons into this factory
# a) because the SphericalFactory#make_valid method doesn't work
# b) 2D Cartesian mapping is fine for this implmentation, as we're UK only and don't care (enough) about the Earth being spherical for job searches
GEOS_FACTORY = RGeo::Geos.factory

class << self
def limit_by_location(vacancies, location, radius_in_miles)
if location.blank? || LocationQuery::NATIONWIDE_LOCATIONS.include?(location)
vacancies
else
polygon = LocationPolygon.buffered(radius_in_miles).with_name(location)
if polygon.present?
polygon_area = polygon.area.transform(GEOS_FACTORY).make_valid
polygon_area = LocationPolygon.buffered(radius_in_miles).with_name(location)&.area
if polygon_area.present? && polygon_area.invalid_reason.nil?
vacancies.select { |v| v.organisations.map(&:geopoint).any? { |point| polygon_area.contains?(point) } }
else
radius_in_metres = convert_miles_to_metres radius_in_miles