Skip to content

Commit

Permalink
Add/Remove Indexes - Metadata Table (#1128)
Browse files Browse the repository at this point in the history
* Add missing index on metadata

* refactor the metadata queries

* fix rubocop issue
  • Loading branch information
kaysiz authored Apr 3, 2024
1 parent 1e29b9f commit 1e0cb00
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ def to_jsonapi
end

def current_metadata
metadata.order("metadata.created DESC").first
metadata.first
end

def metadata_version
Expand Down
2 changes: 1 addition & 1 deletion app/models/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def metadata_must_be_valid

def set_metadata_version
current_metadata =
Metadata.where(dataset: dataset).order("metadata.created DESC").first
Metadata.where(dataset: dataset).order("created DESC").first
self.metadata_version =
current_metadata.present? ? current_metadata.metadata_version + 1 : 0
end
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20240215091610_add_indexes_to_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddIndexesToMetadata < ActiveRecord::Migration[6.1]
def change
add_index :metadata, [:dataset, :created], name: "index_metadata_dataset_created"
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.


ActiveRecord::Schema.define(version: 2024_02_29_195058) do

create_table "active_storage_attachments", charset: "utf8mb4", force: :cascade do |t|
Expand Down Expand Up @@ -290,6 +291,7 @@
t.bigint "dataset", null: false
t.binary "is_converted_by_mds", limit: 1
t.string "namespace"
t.index ["dataset", "created"], name: "index_metadata_dataset_created"
t.index ["dataset", "metadata_version"], name: "dataset_version"
t.index ["dataset"], name: "FKE52D7B2F4D3D6B1B"
end
Expand Down

0 comments on commit 1e0cb00

Please sign in to comment.