From 81708d2ef8ecd4afe5bc0875117ca0f5fab2617c Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 11 Jan 2021 21:59:00 -0600 Subject: [PATCH] search: log extra search metadata to NewRelic. When a user does a tag search, log a few more things, including the normalized search string, the number of tags in the search string, and the number of results. --- app/controllers/posts_controller.rb | 1 + app/logical/post_sets/post.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 160a10633..ff51ce9bc 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -12,6 +12,7 @@ class PostsController < ApplicationController tag_query = params[:tags] || params.dig(:post, :tags) @post_set = PostSets::Post.new(tag_query, params[:page], params[:limit], random: params[:random], format: params[:format]) @posts = authorize @post_set.posts, policy_class: PostPolicy + @post_set.log! respond_with(@posts) do |format| format.atom end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index e9a1bb714..5ca2b9c78 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -160,6 +160,24 @@ module PostSets end end + def search_stats + { + query: normalized_query.to_s, + count: post_count, + page: current_page, + limit: per_page, + term_count: normalized_query.terms.count, + tag_count: normalized_query.tags.count, + metatag_count: normalized_query.metatags.count, + censored_posts: censored_posts.count, + hidden_posts: hidden_posts.count, + } + end + + def log! + DanbooruLogger.add_attributes("search", search_stats) + end + concerning :TagListMethods do def related_tags if query.is_wildcard_search?