Skip to content

move from current and next term to all active terms#408

Merged
jaspermayone merged 5 commits into
mainfrom
fix/369/terms
Jun 5, 2026
Merged

move from current and next term to all active terms#408
jaspermayone merged 5 commits into
mainfrom
fix/369/terms

Conversation

@miretskydatwit

Copy link
Copy Markdown
Member

Closes #369

Comment thread app/models/term.rb Outdated
@jaspermayone jaspermayone marked this pull request as draft March 7, 2026 14:58
@jaspermayone

Copy link
Copy Markdown
Member

@miretskydatwit pls convert back from draft when you've tested :)

Thx!

@jaspermayone

Copy link
Copy Markdown
Member

Two issues worth fixing before this merges:

1. N+1 query in scope :active

active_terms = all.select do |term|
  reg_start = term.registration_start  # fires a SQL query per term
  ...
end

all.select loads every term into Ruby, then registration_start fires a separate UniversityCalendarEvent query for each one. With 10 terms that's 11 queries; it'll only get worse over time.

Options:

  • Preload with includes(:university_calendar_events) before the .select (Term would need a has_many :university_calendar_events)
  • Or rewrite as a single SQL subquery — something like where("start_date <= ? AND end_date >= ?", today, today).where("id IN (SELECT term_id FROM university_calendar_events WHERE category = 'registration' AND ...)")

The Ruby-level filtering approach is fine for small datasets in tests, but will hurt in prod.


2. Fragile %registration%open% ILIKE filter in registration_start

.where("summary ILIKE ?", "%registration%open%")

This requires the summary to contain both "registration" and "open" in that order. Real university calendar events could say "Open Registration", "Registration Begins", "Registration Period", "Priority Registration", etc. — all of which would be silently missed, causing the fallback to start_date instead of the actual registration open date.

Suggest either:

  • Relaxing the filter to just %registration% (the scope already filters to category: 'registration', so the summary filter may not be needed at all)
  • Or checking against actual event summaries in production data before locking in this pattern

@jaspermayone jaspermayone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@miretskydatwit plz address above feedback before marking as ready :)

jaspermayone

This comment was marked as duplicate.

@jaspermayone

Copy link
Copy Markdown
Member

weird that went twice lol

@miretskydatwit miretskydatwit marked this pull request as ready for review March 15, 2026 18:28
@miretskydatwit miretskydatwit self-assigned this Mar 15, 2026
Comment thread .devcontainer/docker-compose.yml
Comment thread app/jobs/pghero_capture_query_stats_job.rb
Comment thread app/jobs/pghero_capture_space_stats_job.rb
Comment thread app/models/term.rb Outdated
Comment thread app/models/term.rb
Comment thread docs/term-dates.md
Comment thread spec/jobs/pghero_capture_query_stats_job_spec.rb
Comment thread spec/jobs/pghero_capture_space_stats_job_spec.rb
Comment thread spec/requests/api/misc_spec.rb
Comment thread Procfile.dev
Comment thread app/jobs/university_calendar_sync_job.rb Outdated
Comment thread app/models/term.rb Outdated
Comment thread spec/models/term_spec.rb
@miretskydatwit

miretskydatwit commented Mar 17, 2026

Copy link
Copy Markdown
Member Author

@jaspermayone (preferably before you review this PR again) pls review and merge #439 and after merging that, pls merge from main into this branch (fix/369/terms). Thanks!

@miretskydatwit

Copy link
Copy Markdown
Member Author

@jaspermayone bump, pls review, thx! i do see rspec is failing but not entirely sure why.

@jaspermayone

Copy link
Copy Markdown
Member

This should kind of get solved with the rewrite, but I'll check in on it

* hi

* fix codespace

* apply jasper's suggestions

---------

Signed-off-by: Daniel Miretsky <miretskyd@wit.edu>
* hi

* fix codespace

* apply jasper's suggestions

* fix misc spec

* fix misc spec

* fix term start and end dates

---------

Signed-off-by: Daniel Miretsky <miretskyd@wit.edu>
@jaspermayone jaspermayone added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit 152af87 Jun 5, 2026
4 of 5 checks passed
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.

move from current and next term to available terms

2 participants