-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tags to representation document (#6309)
* Read tags from new field * Sync analysis tags into search index document * Update app/commands/exercise/representation/create_search_index_document.rb Co-authored-by: Jeremy Walker <jez.walker@gmail.com> * Add memoization * Fix rubocop * Add Exercise::Tag and Solution::Tag * Store exercise and solution tags * Process tags.json file * Prevent loading of relationship * Change order of columns in migration * Add bugsnags when process tooling job output * Remove n+1 in updating exercise tags * Remove n+1 in updating solution tags * Fix test runner flow tests --------- Co-authored-by: Jeremy Walker <jez.walker@gmail.com>
- Loading branch information
1 parent
c42aaf2
commit 67e68ed
Showing
31 changed files
with
440 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Exercise::UpdateTags | ||
include Mandate | ||
|
||
initialize_with :exercise | ||
|
||
def call = exercise.update(tags:) | ||
|
||
private | ||
def tags | ||
solution_tags = Solution::Tag.where(exercise:).distinct.pluck(:tag) | ||
existing_tags = Exercise::Tag.where(exercise:).where(tag: solution_tags).select(:id, :tag).to_a | ||
exercise_tags = existing_tags.map(&:tag) | ||
|
||
new_tags = (solution_tags - exercise_tags).map do |tag| | ||
Exercise::Tag.find_or_create_by!(tag:, exercise:) | ||
end | ||
|
||
existing_tags + new_tags | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Solution::UpdateTags | ||
include Mandate | ||
|
||
initialize_with :solution | ||
|
||
def call | ||
solution.update(tags:) | ||
Exercise::UpdateTags.(solution.exercise) | ||
end | ||
|
||
private | ||
def tags | ||
return [] if latest_analysis.nil? | ||
|
||
analysis_tags = latest_analysis.tags | ||
existing_tags = Solution::Tag.where(solution:).where(tag: analysis_tags).select(:id, :tag).to_a | ||
solution_tags = existing_tags.map(&:tag) | ||
|
||
new_tags = (analysis_tags - solution_tags).map do |tag| | ||
Solution::Tag.find_or_create_by!(tag:, solution:) | ||
end | ||
|
||
existing_tags + new_tags | ||
end | ||
|
||
memoize | ||
def latest_analysis = solution.latest_published_iteration_submission&.analysis | ||
end |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Exercise::Tag < ApplicationRecord | ||
extend Mandate::Memoize | ||
|
||
belongs_to :exercise | ||
|
||
memoize | ||
def category = tag.split(':').first | ||
|
||
memoize | ||
def name = tag.split(':').second | ||
|
||
memoize | ||
def to_s = "#{category.titleize}: #{name.titleize}" | ||
end |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Solution::Tag < ApplicationRecord | ||
extend Mandate::Memoize | ||
|
||
belongs_to :solution | ||
belongs_to :exercise | ||
belongs_to :user | ||
|
||
before_validation on: :create do | ||
self.exercise_id = solution.exercise_id unless exercise_id | ||
self.user_id = solution.user_id unless user_id | ||
end | ||
|
||
memoize | ||
def category = tag.split(':').first | ||
|
||
memoize | ||
def name = tag.split(':').second | ||
|
||
memoize | ||
def to_s = "#{category.titleize}: #{name.titleize}" | ||
end |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddTagsToSubmissionAnalyses < ActiveRecord::Migration[7.0] | ||
def change | ||
return if Rails.env.production? | ||
|
||
add_column :submission_analyses, :tags_data, :text, null: true | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateSolutionTags < ActiveRecord::Migration[7.0] | ||
def change | ||
return if Rails.env.production? | ||
|
||
create_table :solution_tags do |t| | ||
t.references :solution, null: false, foreign_key: true | ||
t.references :exercise, null: false, foreign_key: true | ||
t.references :user, null: false, foreign_key: true | ||
|
||
t.string :tag, null: false | ||
|
||
t.index %i[solution_id tag], unique: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateExerciseTags < ActiveRecord::Migration[7.0] | ||
def change | ||
return if Rails.env.production? | ||
|
||
create_table :exercise_tags do |t| | ||
t.references :exercise, null: false, foreign_key: true | ||
|
||
t.string :tag, null: false | ||
t.boolean :filterable, null: false, default: true | ||
|
||
t.index %i[exercise_id tag], unique: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
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
Oops, something went wrong.