Skip to content

Commit 7ef7b99

Browse files
Add unique index on documents.source_url to fix slow uniqueness valid… (#246)
* Add unique index on documents.source_url to fix slow uniqueness validation The uniqueness validation on source_url was doing a full table scan on every document save. This adds a partial unique index excluding NULL and empty string values, matching the `if: -> { source_url.present? }` condition. Made-with: Cursor * Update dependencies in Gemfile and Gemfile.lock to address security vulnerabilities - Added 'nokogiri' version 1.19.1 to fix GHSA-wx95-c6cv-8532 and CVE-2026-22860, CVE-2026-25500. - Updated 'rack' to version 3.1.20 for improved security and compatibility. * Update Ruby version to 3.3.8 in .ruby-version, Gemfile, and GitHub Actions workflow - Updated Ruby version from 3.2.2 to 3.3.8 in .ruby-version and Gemfile for compatibility. - Adjusted GitHub Actions workflow to use the new Ruby version for CI/CD processes. - Updated Gemfile.lock to reflect the new Ruby version.
1 parent 2d31025 commit 7ef7b99

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

.github/workflows/rubyonrails.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Install Ruby and gems
5050
uses: ruby/setup-ruby@v1
5151
with:
52-
ruby-version: '3.2.2'
52+
ruby-version: '3.3.8'
5353
bundler-cache: true
5454
# Add or replace any other lints here
5555
- name: Security audit dependencies

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.2
1+
3.3.8

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source 'https://rubygems.org'
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6-
ruby '3.2.2'
6+
ruby '3.3.8'
77

88
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
99
gem 'rails', '~> 7.2.0'
@@ -94,6 +94,10 @@ gem 'httparty', '>= 0.24.0'
9494
# Security: Fix CVE-2026-25765 (SSRF vulnerability)
9595
gem 'faraday', '>= 2.14.1', '< 3.0'
9696

97+
# Security: Fix GHSA-wx95-c6cv-8532 (nokogiri), CVE-2026-22860, CVE-2026-25500 (rack)
98+
gem 'nokogiri', '>= 1.19.1'
99+
gem 'rack', '~> 3.1.20'
100+
97101
# Markdown renderer
98102
gem 'redcarpet'
99103

Gemfile.lock

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ GEM
265265
net-protocol
266266
nio4r (2.7.4)
267267
nkf (0.2.0)
268-
nokogiri (1.18.9-arm64-darwin)
268+
nokogiri (1.19.1-arm64-darwin)
269269
racc (~> 1.4)
270-
nokogiri (1.18.9-x86_64-darwin)
270+
nokogiri (1.19.1-x86_64-darwin)
271271
racc (~> 1.4)
272-
nokogiri (1.18.9-x86_64-linux-gnu)
272+
nokogiri (1.19.1-x86_64-linux-gnu)
273273
racc (~> 1.4)
274274
nori (2.7.1)
275275
bigdecimal
@@ -322,7 +322,7 @@ GEM
322322
pundit (2.5.0)
323323
activesupport (>= 3.0.0)
324324
racc (1.8.1)
325-
rack (3.1.18)
325+
rack (3.1.20)
326326
rack-cors (3.0.0)
327327
logger
328328
rack (>= 3.0.14)
@@ -536,6 +536,7 @@ PLATFORMS
536536
arm64-darwin-24
537537
arm64-darwin-25
538538
x86_64-darwin-22
539+
x86_64-darwin-25
539540
x86_64-linux
540541

541542
DEPENDENCIES
@@ -559,6 +560,7 @@ DEPENDENCIES
559560
jbuilder
560561
kaminari
561562
neighbor
563+
nokogiri (>= 1.19.1)
562564
omniauth-google-oauth2
563565
optparse
564566
pager_duty-connection
@@ -567,6 +569,7 @@ DEPENDENCIES
567569
pgvector
568570
puma (~> 6.4)
569571
pundit (~> 2.3)
572+
rack (~> 3.1.20)
570573
rack-cors
571574
rails (~> 7.2.0)
572575
rails-controller-testing
@@ -594,7 +597,7 @@ DEPENDENCIES
594597
websocket-client-simple
595598

596599
RUBY VERSION
597-
ruby 3.2.2p53
600+
ruby 3.3.8p144
598601

599602
BUNDLED WITH
600603
2.4.13
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class AddIndexToDocumentsSourceUrl < ActiveRecord::Migration[7.1]
4+
disable_ddl_transaction!
5+
6+
def change
7+
remove_index :documents, :source_url, if_exists: true
8+
add_index :documents, :source_url, unique: true, where: "source_url IS NOT NULL AND source_url != ''", algorithm: :concurrently
9+
end
10+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)