diff --git a/app/controllers/concerns/bulkrax/datatables_behavior.rb b/app/controllers/concerns/bulkrax/datatables_behavior.rb index 46cbecb4..570ac18d 100644 --- a/app/controllers/concerns/bulkrax/datatables_behavior.rb +++ b/app/controllers/concerns/bulkrax/datatables_behavior.rb @@ -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 diff --git a/app/models/bulkrax/status.rb b/app/models/bulkrax/status.rb index 86c850b0..a8df74ba 100644 --- a/app/models/bulkrax/status.rb +++ b/app/models/bulkrax/status.rb @@ -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 diff --git a/db/migrate/20241203010707_entry_error_denormalization.rb b/db/migrate/20241203010707_entry_error_denormalization.rb new file mode 100644 index 00000000..9cfef36e --- /dev/null +++ b/db/migrate/20241203010707_entry_error_denormalization.rb @@ -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 diff --git a/db/migrate/20241205212513_faster_first_entry.rb b/db/migrate/20241205212513_faster_first_entry.rb new file mode 100644 index 00000000..e0ac8804 --- /dev/null +++ b/db/migrate/20241205212513_faster_first_entry.rb @@ -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 diff --git a/lib/tasks/bulkrax_tasks.rake b/lib/tasks/bulkrax_tasks.rake index 18b5b8e1..4f597874 100644 --- a/lib/tasks/bulkrax_tasks.rake +++ b/lib/tasks/bulkrax_tasks.rake @@ -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 diff --git a/spec/test_app/db/schema.rb b/spec/test_app/db/schema.rb index cdaa0933..f14b49ad 100644 --- a/spec/test_app/db/schema.rb +++ b/spec/test_app/db/schema.rb @@ -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" @@ -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 @@ -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 @@ -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