summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Lopez <fjlopez@gitlab.com>2017-11-30 14:01:56 +0100
committerFrancisco Lopez <fjlopez@gitlab.com>2017-12-01 18:32:12 +0100
commitfa6b0a36bd315a4777bb8b3229b89808b95a9489 (patch)
tree524aa45c117b2f2f9dce69d189c2f8bfdb7cfe39
parent966f83f9653aa774ee82be65dbdae0c6e4f297da (diff)
downloadgitlab-ce-fa6b0a36bd315a4777bb8b3229b89808b95a9489.tar.gz
Changes after rebase
-rw-r--r--lib/api/entities.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index dada353a314..e0eb2ecfb73 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -87,14 +87,25 @@ module API
expose :created_at
end
- class BasicProjectDetails < ProjectIdentity
- expose :default_branch, :tag_list
+ class BasicProjectDetails < Grape::Entity
+ include ::API::ProjectsRelationBuilder
+
+ expose :default_branch
+
+ # Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
+ expose :tag_list do |project|
+ # project.tags.order(:name).pluck(:name) is the most suitable option
+ # to avoid loading all the ActiveRecord objects but, if we use it here
+ # it override the preloaded associations and makes a query
+ # (fixed in https://github.com/rails/rails/pull/25976).
+ project.tags.map(&:name).sort
+ end
expose :ssh_url_to_repo, :http_url_to_repo, :web_url
expose :avatar_url do |project, options|
project.avatar_url(only_path: false)
end
expose :star_count, :forks_count
- expose :created_at, :last_activity_at
+ expose :last_activity_at
def self.preload_relation(projects_relation, options = {})
projects_relation.preload(:project_feature, :route)