summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-11-28 17:06:04 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-28 17:10:12 +0100
commit631801674f0cc6b0ccf7ba7dc8ad621d21e62105 (patch)
tree517f504d9530b54f4dc152bc6c7905bd0a81efc9
parent52f5259ae40cfd868c6412ba10e28dc83877afbb (diff)
downloadgitlab-ce-events-atom-feed-author-query.tar.gz
Reuse authors when rendering event Atom feedsevents-atom-feed-author-query
Previously we'd use "event.author_email" which translates to "event.author.email". This would result in an extra query being executed _for every event_ just to get the same author's Email address. Instead of doing all this useless work we can just pass the User object returned by "event.author" since: 1. This allows us to re-use the user object's Email address. 2. Authors are eager-loaded, so this doesn't cause any N+1 queries.
-rw-r--r--app/views/events/_event.atom.builder7
-rw-r--r--changelogs/unreleased/events-atom-feed-author-query.yml5
2 files changed, 11 insertions, 1 deletions
diff --git a/app/views/events/_event.atom.builder b/app/views/events/_event.atom.builder
index e2aec532a9d..38741fe6662 100644
--- a/app/views/events/_event.atom.builder
+++ b/app/views/events/_event.atom.builder
@@ -5,7 +5,12 @@ xml.entry do
xml.link href: event_feed_url(event)
xml.title truncate(event_feed_title(event), length: 80)
xml.updated event.updated_at.xmlschema
- xml.media :thumbnail, width: "40", height: "40", url: image_url(avatar_icon(event.author_email))
+
+ # We're deliberately re-using "event.author" here since this data is
+ # eager-loaded. This allows us to re-use the user object's Email address,
+ # instead of having to run additional queries to figure out what Email to use
+ # for the avatar.
+ xml.media :thumbnail, width: "40", height: "40", url: image_url(avatar_icon(event.author))
xml.author do
xml.username event.author_username
diff --git a/changelogs/unreleased/events-atom-feed-author-query.yml b/changelogs/unreleased/events-atom-feed-author-query.yml
new file mode 100644
index 00000000000..84c51f25de7
--- /dev/null
+++ b/changelogs/unreleased/events-atom-feed-author-query.yml
@@ -0,0 +1,5 @@
+---
+title: Reuse authors when rendering event Atom feeds
+merge_request:
+author:
+type: performance