Skip to content

Commit 156fc6f

Browse files
authored
Merge pull request #489 from DigitalCurationCentre/xsrust/bugfixes
Xsrust/bugfixes
2 parents 0e21881 + 34c37e7 commit 156fc6f

File tree

6 files changed

+82
-24
lines changed

6 files changed

+82
-24
lines changed

app/controllers/phases_controller.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ def edit
2929
# where guidance is a hash with the text and the org name
3030
theme_guidance = {}
3131

32-
guidance_groups.each do |guidance_group|
33-
guidance_group.guidances.where(published: true).each do |guidance|
34-
guidance.themes.each do |theme|
35-
title = theme.title
36-
if !theme_guidance.has_key?(title)
37-
theme_guidance[title] = Array.new
32+
guidance_groups.includes(guidances:[:themes]).each do |guidance_group|
33+
guidance_group.guidances.each do |guidance|
34+
if guidance.published
35+
guidance.themes.each do |theme|
36+
title = theme.title
37+
if !theme_guidance.has_key?(title)
38+
theme_guidance[title] = Array.new
39+
end
40+
theme_guidance[title] << {
41+
text: guidance.text,
42+
org: guidance_group.name + ':'
43+
}
3844
end
39-
theme_guidance[title] << {
40-
text: guidance.text,
41-
org: guidance_group.name + ':'
42-
}
4345
end
4446
end
4547
end

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def admin_update_permissions
4141
else
4242
if perms.include? perm
4343
@user.perms << perm
44-
if perm.name == Perm.use_api.id
44+
if perm.id == Perm.use_api.id
4545
@user.keep_or_generate_token!
4646
end
4747
end

app/models/plan.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def get_guidance_group_options
159159
# find all the themes in this plan
160160
# and get the guidance groups they belong to
161161
ggroups = []
162-
self.template.phases.each do |phase|
162+
Template.includes(phases: [sections: [questions: [themes: [guidances: [guidance_group: :org]]]]]).find(self.template_id).phases.each do |phase|
163163
phase.sections.each do |section|
164164
section.questions.each do |question|
165165
question.themes.each do |theme|

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def filter(query)
5353

5454
##
5555
# Scopes
56-
default_scope { includes(:org, :perms, :plans) }
56+
default_scope { includes(:org, :perms) }
5757

5858

5959

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class EnsureIndexesInPlace < ActiveRecord::Migration
2+
def change
3+
#users_perms
4+
remove_index :users_perms, name: 'index_users_perms_on_user_id_and_perm_id'
5+
add_index :users_perms, :user_id
6+
#user_identifiers
7+
add_index :user_identifiers, :user_id
8+
#roles
9+
add_index :roles, :user_id
10+
add_index :roles, :plan_id
11+
#org_token_permissions
12+
add_index :org_token_permissions, :org_id
13+
#users
14+
add_index :users, :org_id
15+
remove_index :users, :confirmation_token
16+
remove_index :users, :invitation_token
17+
remove_index :users, :reset_password_token
18+
#notes
19+
add_index :notes, :answer_id
20+
#guidance_groups
21+
add_index :guidance_groups, :org_id
22+
#guidance
23+
add_index :guidances, :guidance_group_id
24+
#themes_in_guidance
25+
add_index :themes_in_guidance, :theme_id
26+
add_index :themes_in_guidance, :guidance_id
27+
#annotations
28+
add_index :annotations, :question_id
29+
#question_themes
30+
remove_index :questions_themes, name: 'question_theme_index'
31+
remove_index :questions_themes, name: 'theme_question_index'
32+
add_index :questions_themes, :question_id
33+
#question_options
34+
add_index :question_options, :question_id
35+
#answers_question_options
36+
remove_index :answers_question_options, name: 'answer_question_option_index'
37+
remove_index :answers_question_options, name: 'question_option_answer_index'
38+
add_index :answers_question_options, :answer_id
39+
end
40+
end

db/schema.rb

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20170428083711) do
14+
ActiveRecord::Schema.define(version: 20170702012742) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -25,6 +25,8 @@
2525
t.datetime "updated_at"
2626
end
2727

28+
add_index "annotations", ["question_id"], name: "index_annotations_on_question_id", using: :btree
29+
2830
create_table "answers", force: :cascade do |t|
2931
t.text "text"
3032
t.integer "plan_id"
@@ -40,8 +42,7 @@
4042
t.integer "question_option_id", null: false
4143
end
4244

43-
add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree
44-
add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index", using: :btree
45+
add_index "answers_question_options", ["answer_id"], name: "index_answers_question_options_on_answer_id", using: :btree
4546

4647
create_table "exported_plans", force: :cascade do |t|
4748
t.integer "plan_id"
@@ -93,6 +94,8 @@
9394
t.boolean "published"
9495
end
9596

97+
add_index "guidance_groups", ["org_id"], name: "index_guidance_groups_on_org_id", using: :btree
98+
9699
create_table "guidances", force: :cascade do |t|
97100
t.text "text"
98101
t.integer "guidance_group_id"
@@ -102,6 +105,8 @@
102105
t.boolean "published"
103106
end
104107

108+
add_index "guidances", ["guidance_group_id"], name: "index_guidances_on_guidance_group_id", using: :btree
109+
105110
create_table "identifier_schemes", force: :cascade do |t|
106111
t.string "name"
107112
t.string "description"
@@ -129,13 +134,17 @@
129134
t.datetime "updated_at"
130135
end
131136

137+
add_index "notes", ["answer_id"], name: "index_notes_on_answer_id", using: :btree
138+
132139
create_table "org_token_permissions", force: :cascade do |t|
133140
t.integer "org_id"
134141
t.integer "token_permission_type_id"
135142
t.datetime "created_at"
136143
t.datetime "updated_at"
137144
end
138145

146+
add_index "org_token_permissions", ["org_id"], name: "index_org_token_permissions_on_org_id", using: :btree
147+
139148
create_table "orgs", force: :cascade do |t|
140149
t.string "name"
141150
t.string "abbreviation"
@@ -219,6 +228,8 @@
219228
t.datetime "updated_at"
220229
end
221230

231+
add_index "question_options", ["question_id"], name: "index_question_options_on_question_id", using: :btree
232+
222233
create_table "questions", force: :cascade do |t|
223234
t.text "text"
224235
t.text "default_value"
@@ -238,8 +249,7 @@
238249
t.integer "theme_id", null: false
239250
end
240251

241-
add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index", using: :btree
242-
add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index", using: :btree
252+
add_index "questions_themes", ["question_id"], name: "index_questions_themes_on_question_id", using: :btree
243253

244254
create_table "regions", force: :cascade do |t|
245255
t.string "abbreviation"
@@ -256,6 +266,9 @@
256266
t.integer "access", default: 0, null: false
257267
end
258268

269+
add_index "roles", ["plan_id"], name: "index_roles_on_plan_id", using: :btree
270+
add_index "roles", ["user_id"], name: "index_roles_on_user_id", using: :btree
271+
259272
create_table "sections", force: :cascade do |t|
260273
t.string "title"
261274
t.text "description"
@@ -319,6 +332,9 @@
319332
t.integer "guidance_id"
320333
end
321334

335+
add_index "themes_in_guidance", ["guidance_id"], name: "index_themes_in_guidance_on_guidance_id", using: :btree
336+
add_index "themes_in_guidance", ["theme_id"], name: "index_themes_in_guidance_on_theme_id", using: :btree
337+
322338
create_table "token_permission_types", force: :cascade do |t|
323339
t.string "token_type"
324340
t.text "text_description"
@@ -334,14 +350,16 @@
334350
t.integer "identifier_scheme_id"
335351
end
336352

353+
add_index "user_identifiers", ["user_id"], name: "index_user_identifiers_on_user_id", using: :btree
354+
337355
create_table "users", force: :cascade do |t|
338356
t.string "firstname"
339357
t.string "surname"
340358
t.string "email", default: "", null: false
341359
t.string "orcid_id"
342360
t.string "shibboleth_id"
343-
t.datetime "created_at"
344-
t.datetime "updated_at"
361+
t.datetime "created_at", null: false
362+
t.datetime "updated_at", null: false
345363
t.string "encrypted_password", default: ""
346364
t.string "reset_password_token"
347365
t.datetime "reset_password_sent_at"
@@ -367,17 +385,15 @@
367385
t.integer "language_id"
368386
end
369387

370-
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
371388
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
372-
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
373-
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
389+
add_index "users", ["org_id"], name: "index_users_on_org_id", using: :btree
374390

375391
create_table "users_perms", id: false, force: :cascade do |t|
376392
t.integer "user_id"
377393
t.integer "perm_id"
378394
end
379395

380-
add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree
396+
add_index "users_perms", ["user_id"], name: "index_users_perms_on_user_id", using: :btree
381397

382398
add_foreign_key "annotations", "orgs"
383399
add_foreign_key "annotations", "questions"

0 commit comments

Comments
 (0)