Skip to content

Commit d53b5e2

Browse files
Doc perf (#245)
* Add migration to add indexes on documents for improved list performance * Enhance document listing performance by avoiding heavy column loading when not needed. Update Gemfile.lock for arm64-darwin-25 support and adjust database schema version. Remove unused index and add new indexes for improved query performance. * Refactor document loading to improve performance by excluding the document body from heavy column loading in the list view.
1 parent f496d73 commit d53b5e2

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ PLATFORMS
534534
arm64-darwin-22
535535
arm64-darwin-23
536536
arm64-darwin-24
537+
arm64-darwin-25
537538
x86_64-darwin-22
538539
x86_64-linux
539540

app/controllers/base_documents_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ def index
7474
end
7575
end
7676

77+
# Avoid loading heavy columns (document body, embedding vector, search_vector) for list
78+
unless params[:similar_to].present?
79+
heavy = %w[embedding search_vector]
80+
list_columns = (Document.column_names - heavy).map { |c| "documents.#{c}" }
81+
@documents = @documents.select(list_columns.join(", "))
82+
end
83+
7784
@documents = @documents.page(params[:page]).per(params[:per_page] || 10)
7885
end
7986

app/views/shared/_doc_list.html.erb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,7 @@
4545
</svg>
4646
Disabled
4747
</div>
48-
<% end %>
49-
<% if document.embedding.nil? %>
50-
<div class="flex items-center text-purple-500">
51-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-3 h-3 mr-1">
52-
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" />
53-
</svg>
54-
Processing
55-
</div>
56-
<% end %>
57-
48+
<% end %>
5849
</div>
5950
</div>
6051
<a href="<%= url_for(document) %>" class="inline-flex items-center text-sky-700 hover:text-white hover:bg-sky-500 px-4 py-2 rounded-full transition-all">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
class AddIndexesToDocumentsForListPerformance < ActiveRecord::Migration[7.1]
4+
def change
5+
add_index :documents, :updated_at
6+
add_index :documents, :deleted_date
7+
add_index :documents, [:deleted_date, :updated_at]
8+
end
9+
end

db/schema.rb

Lines changed: 4 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)