From e3e7da3f52fe879e09ab369424d469892d0ae917 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 25 Oct 2017 20:23:06 +1030 Subject: [PATCH 1/3] Add class to IndexPage when viewing a tag --- extensions/tags/js/forum/dist/extension.js | 8 ++++++++ extensions/tags/js/forum/src/addTagFilter.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/extensions/tags/js/forum/dist/extension.js b/extensions/tags/js/forum/dist/extension.js index bbe7b6b81..441360706 100644 --- a/extensions/tags/js/forum/dist/extension.js +++ b/extensions/tags/js/forum/dist/extension.js @@ -150,6 +150,14 @@ System.register('flarum/tags/addTagFilter', ['flarum/extend', 'flarum/components return original(); }); + extend(IndexPage.prototype, 'view', function (vdom) { + var tag = this.currentTag(); + + if (tag) { + vdom.attrs.className += ' IndexPage--tag' + tag.id(); + } + }); + // If currently viewing a tag, restyle the 'new discussion' button to use // the tag's color. extend(IndexPage.prototype, 'sidebarItems', function (items) { diff --git a/extensions/tags/js/forum/src/addTagFilter.js b/extensions/tags/js/forum/src/addTagFilter.js index 5ec5acb3d..1392d144e 100644 --- a/extensions/tags/js/forum/src/addTagFilter.js +++ b/extensions/tags/js/forum/src/addTagFilter.js @@ -20,6 +20,14 @@ export default function() { return original(); }); + extend(IndexPage.prototype, 'view', function(vdom) { + const tag = this.currentTag(); + + if (tag) { + vdom.attrs.className += ' IndexPage--tag'+tag.id(); + } + }); + // If currently viewing a tag, restyle the 'new discussion' button to use // the tag's color. extend(IndexPage.prototype, 'sidebarItems', function(items) { From 6a21d292c5e626fbb59da2b902d307f62810e587 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 11 Nov 2017 22:40:22 +1030 Subject: [PATCH 2/3] Performance: Eager load parent tags --- extensions/tags/src/Listener/AddForumTagsRelationship.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/tags/src/Listener/AddForumTagsRelationship.php b/extensions/tags/src/Listener/AddForumTagsRelationship.php index 259d7cdc0..77bcfc029 100755 --- a/extensions/tags/src/Listener/AddForumTagsRelationship.php +++ b/extensions/tags/src/Listener/AddForumTagsRelationship.php @@ -68,7 +68,10 @@ class AddForumTagsRelationship // doesn't actually have a tags relationship, we will manually load and // assign the tags data to it using an event listener. if ($event->isController(ShowForumController::class)) { - $event->data['tags'] = Tag::whereVisibleTo($event->actor)->withStateFor($event->actor)->with('lastDiscussion')->get(); + $event->data['tags'] = Tag::whereVisibleTo($event->actor) + ->withStateFor($event->actor) + ->with(['parent', 'lastDiscussion']) + ->get(); } } From 89f417097bbbd2442844bba33f745ff7f9680f55 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 11 Nov 2017 22:40:48 +1030 Subject: [PATCH 3/3] Performance: Load only basic information about lastDiscussion --- extensions/tags/src/Api/Serializer/TagSerializer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/tags/src/Api/Serializer/TagSerializer.php b/extensions/tags/src/Api/Serializer/TagSerializer.php index 8979456b1..da61ad5e4 100644 --- a/extensions/tags/src/Api/Serializer/TagSerializer.php +++ b/extensions/tags/src/Api/Serializer/TagSerializer.php @@ -12,7 +12,7 @@ namespace Flarum\Tags\Api\Serializer; use Flarum\Api\Serializer\AbstractSerializer; -use Flarum\Api\Serializer\DiscussionSerializer; +use Flarum\Api\Serializer\DiscussionBasicSerializer; class TagSerializer extends AbstractSerializer { @@ -64,6 +64,6 @@ class TagSerializer extends AbstractSerializer */ protected function lastDiscussion($tag) { - return $this->hasOne($tag, DiscussionSerializer::class); + return $this->hasOne($tag, DiscussionBasicSerializer::class); } }