From aa41fc8fbda88120a783ff3c945f6723ecbc8934 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Fri, 27 Oct 2023 22:29:54 +0900 Subject: [PATCH] Show upload count on community solutions (#6407) * Show upload count on community solutions * Add `published_exercise_representation` to `solutions_with_includes` * Try a different format * Fix serialize_community_solution_test * Fix n+1 --------- Co-authored-by: dem4ron --- .../tracks/community_solutions_controller.rb | 2 +- app/images/icons/upload.svg | 5 +++ .../components/common/CommunitySolution.tsx | 42 ++++++++++++++----- app/javascript/components/types.ts | 1 + app/models/exercise/representation.rb | 1 - .../serialize_community_solution.rb | 1 + .../serialize_community_solutions.rb | 2 +- .../serialize_community_solution_test.rb | 1 + 8 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 app/images/icons/upload.svg diff --git a/app/controllers/tracks/community_solutions_controller.rb b/app/controllers/tracks/community_solutions_controller.rb index 4bd2d111b3..b4b890c4b5 100644 --- a/app/controllers/tracks/community_solutions_controller.rb +++ b/app/controllers/tracks/community_solutions_controller.rb @@ -41,7 +41,7 @@ def show # We want to manually exclude (after SQL!) the solution id, and then just select 3 (os_ids - [@solution.id])[0, 3] - @other_solutions = Solution.where(id: os_ids).includes(*SerializeSolutions::NP1_INCLUDES) + @other_solutions = Solution.where(id: os_ids).includes(*SerializeSolutions::NP1_INCLUDES + [:published_exercise_representation]) @mentor_discussions = @solution.mentor_discussions.finished.not_negatively_rated.includes(:mentor) @exercise_representation = @solution.published_exercise_representation diff --git a/app/images/icons/upload.svg b/app/images/icons/upload.svg new file mode 100644 index 0000000000..960b7e5c68 --- /dev/null +++ b/app/images/icons/upload.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/app/javascript/components/common/CommunitySolution.tsx b/app/javascript/components/common/CommunitySolution.tsx index cfd4823a1c..ee02118b33 100644 --- a/app/javascript/components/common/CommunitySolution.tsx +++ b/app/javascript/components/common/CommunitySolution.tsx @@ -19,23 +19,43 @@ const PublishDetails = ({ solution }: { solution: CommunitySolutionProps }) => { solution.publishedAt )}`}
+ {solution.representationNumPublishedSolutions ? ( +
+ +
+ {solution.representationNumPublishedSolutions} +
+
+ ) : null} {solution.numLoc ? ( -
- +
+
{solution.numLoc}
) : null} -
- +
+
{solution.numStars}
-
- -
{solution.numComments}
-
+ {solution.numComments && + !solution.representationNumPublishedSolutions ? ( +
+ +
{solution.numComments}
+
+ ) : null}
) diff --git a/app/javascript/components/types.ts b/app/javascript/components/types.ts index e3507a4c7c..1ffcc710c0 100644 --- a/app/javascript/components/types.ts +++ b/app/javascript/components/types.ts @@ -169,6 +169,7 @@ export type CommunitySolution = { numLoc?: string numStars: string numComments: string + representationNumPublishedSolutions: string publishedAt: string language: string iterationStatus: IterationStatus diff --git a/app/models/exercise/representation.rb b/app/models/exercise/representation.rb index fdc3b78b78..4fc00c25cc 100644 --- a/app/models/exercise/representation.rb +++ b/app/models/exercise/representation.rb @@ -58,7 +58,6 @@ def has_feedback? end def appears_frequently? = num_submissions >= APPEARS_FREQUENTLY_MIN_NUM_SUBMISSIONS - def first_submitted_at = oldest_solution.published_iterations.last.created_at def max_reputation = prestigious_solution.user.reputation diff --git a/app/serializers/serialize_community_solution.rb b/app/serializers/serialize_community_solution.rb index f770291ac7..369789ef45 100644 --- a/app/serializers/serialize_community_solution.rb +++ b/app/serializers/serialize_community_solution.rb @@ -10,6 +10,7 @@ def call num_views: solution.num_views, num_stars: solution.num_stars, num_comments: solution.num_comments, + representation_num_published_solutions: solution.published_exercise_representation&.num_published_solutions, num_iterations: solution.num_iterations, num_loc: solution.num_loc.presence, # Currently this column is not-null in production iteration_status: solution.iteration_status, diff --git a/app/serializers/serialize_community_solutions.rb b/app/serializers/serialize_community_solutions.rb index be16edfe54..d79fba74b2 100644 --- a/app/serializers/serialize_community_solutions.rb +++ b/app/serializers/serialize_community_solutions.rb @@ -11,6 +11,6 @@ def call def solutions_with_includes solutions.to_active_relation. - includes(:exercise, :track, :user) + includes(:exercise, :track, :user, :published_exercise_representation) end end diff --git a/test/serializers/serialize_community_solution_test.rb b/test/serializers/serialize_community_solution_test.rb index 29ba6a5517..d9af8aa170 100644 --- a/test/serializers/serialize_community_solution_test.rb +++ b/test/serializers/serialize_community_solution_test.rb @@ -11,6 +11,7 @@ class SerializeCommunitySolutionTest < ActiveSupport::TestCase num_views: solution.num_views, num_stars: solution.num_stars, num_comments: solution.num_comments, + representation_num_published_solutions: solution.published_exercise_representation&.num_published_solutions, num_iterations: solution.num_iterations, num_loc: nil, iteration_status: iteration.status.to_s.to_sym,