Skip to content

Commit

Permalink
speed up entries display by no longer looking at all the status objec…
Browse files Browse the repository at this point in the history
…ts (#988)

* speed up entries display by no longer looking at all the statusable objects

* update importer an exporter too

* fixing importers/exporters

* migration version fix

* improve initial importer show page load time
  • Loading branch information
orangewolf authored and sephirothkod committed Dec 17, 2024
1 parent f2506de commit d1432e8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/bulkrax/datatables_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def format_entries(entries, item)
status_message: status_message_for(e),
type: e.type,
updated_at: e.updated_at,
errors: e.latest_status&.error_class&.present? ? view_context.link_to(e.latest_status.error_class, view_context.item_entry_path(item, e), title: e.latest_status.error_message) : "",
errors: e.status_message == 'Failed' ? view_context.link_to(e.error_class, view_context.item_entry_path(item, e)) : "",
actions: entry_util_links(e, item)
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/bulkrax/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Bulkrax
class Status < ApplicationRecord
belongs_to :statusable, polymorphic: true, denormalize: { fields: %i[status_message], if: :latest? }
belongs_to :statusable, polymorphic: true, denormalize: { fields: %i[status_message error_class], if: :latest? }
belongs_to :runnable, polymorphic: true
serialize :error_backtrace, Array

Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20241203010707_entry_error_denormalization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class EntryErrorDenormalization < ActiveRecord::Migration[5.1]
def change
add_column :bulkrax_entries, :error_class, :string unless column_exists?(:bulkrax_entries, :error_class)
add_column :bulkrax_importers, :error_class, :string unless column_exists?(:bulkrax_importers, :error_class)
add_column :bulkrax_exporters, :error_class, :string unless column_exists?(:bulkrax_exporters, :error_class)
end
end
7 changes: 7 additions & 0 deletions db/migrate/20241205212513_faster_first_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class FasterFirstEntry < ActiveRecord::Migration[5.2]
def change
add_index :bulkrax_entries, [:importerexporter_id, :importerexporter_type, :id], name: 'index_bulkrax_entries_on_importerexporter_id_type_and_id' unless index_exists?(:bulkrax_entries, [:importerexporter_id, :importerexporter_type, :id],
name: 'index_bulkrax_entries_on_importerexporter_id_type_and_id')
end
end
2 changes: 1 addition & 1 deletion lib/tasks/bulkrax_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :bulkrax do
progress_mark: ' ',
remainder_mark: "\u{FF65}")
Bulkrax::Status.latest_by_statusable.includes(:statusable).find_each do |status|
status.statusable.update(status_message: status.status_message)
status.statusable.update(status_message: status.status_message, error_class: status.error_class)
@progress.increment
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_09_16_182823) do
ActiveRecord::Schema.define(version: 2024_12_05_212513) do

create_table "accounts", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -42,7 +42,9 @@
t.string "importerexporter_type", default: "Bulkrax::Importer"
t.integer "import_attempts", default: 0
t.string "status_message", default: "Pending"
t.string "error_class"
t.index ["identifier", "importerexporter_id", "importerexporter_type"], name: "bulkrax_identifier_idx"
t.index ["importerexporter_id", "importerexporter_type", "id"], name: "index_bulkrax_entries_on_importerexporter_id_type_and_id"
t.index ["importerexporter_id", "importerexporter_type"], name: "bulkrax_entries_importerexporter_idx"
t.index ["type"], name: "index_bulkrax_entries_on_type"
end
Expand Down Expand Up @@ -78,6 +80,7 @@
t.boolean "include_thumbnails", default: false
t.boolean "generated_metadata", default: false
t.string "status_message", default: "Pending"
t.string "error_class"
t.index ["user_id"], name: "index_bulkrax_exporters_on_user_id"
end

Expand Down Expand Up @@ -121,6 +124,7 @@
t.string "status_message", default: "Pending"
t.datetime "last_imported_at"
t.datetime "next_import_at"
t.string "error_class"
t.index ["user_id"], name: "index_bulkrax_importers_on_user_id"
end

Expand Down

0 comments on commit d1432e8

Please sign in to comment.