forked from mlc/wnetpbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce the number of ActiveRecord objects generated when loading the …
…Asset editing form
- Loading branch information
Showing
9 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<div class="contributor"> | ||
<p> | ||
<%= f.label(:contributor_role_id, "Contributor Role: ") %> | ||
<%= f.select :contributor_role_id, ContributorRole.all(:conditions => ["visible = 1 OR id = ?", contributor.contributor_role_id]).map{|i| [i.name, i.id]} %> | ||
<%= f.select :contributor_role_id, ContributorRole.quick_load_for_select(["visible = 1 OR id = ?", contributor.contributor_role_id]) %> | ||
| ||
<%= f.label(:contributor, "Contributor:") %> <%= f.text_field :contributor %> | ||
<%= f.remove_link "remove" %> | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<div class="creator"> | ||
<p> | ||
<%= f.label(:creator_role_id, "Creator Role: ") %> | ||
<%= f.select :creator_role_id, CreatorRole.all(:conditions => ["visible = 1 OR id = ?", creator.creator_role_id]).map{|i| [i.name, i.id]} %> | ||
<%= f.select :creator_role_id, CreatorRole.quick_load_for_select(["visible = 1 OR id = ?", creator.creator_role_id]) %> | ||
| ||
<%= f.label(:creator, "Creator:") %> <%= f.text_field :creator %> | ||
<%= f.remove_link "remove" %> | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<div class="subject"> | ||
<p> | ||
<select name="asset[subject_ids][]"> | ||
<%= options_for_select(Subject.all(:conditions => (subject.nil? ? | ||
<%= options_for_select(Subject.quick_load_for_select(subject.nil? ? | ||
"visible = 1" : ["visible = 1 OR id = ?", subject.id]), | ||
:order => "subject ASC").map{|s| ["#{s.subject} (#{s.subject_authority})", s.id]}, subject.id) %> | ||
subject.id) %> | ||
</select> | ||
<%= f.remove_link "remove" %> | ||
</p> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
# A lot of PBCore fields are extensible picklists. | ||
module Picklist | ||
|
||
module ClassMethods | ||
# avoid instantiating lots and lots of ActiveRecord objects when | ||
# all we need is a select box | ||
def quick_load_for_select(conditions = nil) | ||
sql = "SELECT #{get_quick_column} AS quick, id FROM #{connection.quote_table_name(table_name)}" | ||
sanitized_conditions = sanitize_sql_for_conditions(conditions) | ||
sql << " WHERE #{sanitized_conditions}" if sanitized_conditions | ||
sql << " ORDER BY quick ASC" | ||
result = connection.execute(sql) | ||
rows = [] | ||
result.each{|row| rows << row} | ||
result.free | ||
|
||
rows | ||
end | ||
|
||
# set the column or other SQL expression which will be the title | ||
# in quickly-loaded sqlect boxes | ||
def quick_column(column) | ||
write_inheritable_attribute("quick_column", column) | ||
end | ||
|
||
def get_quick_column #:nodoc: | ||
read_inheritable_attribute("quick_column") | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
end |