From b65bf66f9165d2369796776dbcc2df2ebb38ccad Mon Sep 17 00:00:00 2001 From: Sybil <sybil.deboin@gmail.com> Date: Tue, 3 Mar 2015 16:59:06 +0100 Subject: [PATCH] Corrections to the ugly query. --- app/controllers/tags_controller.rb | 5 +++++ app/controllers/tracks_controller.rb | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index a01b30e..902cd91 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -5,4 +5,9 @@ class TagsController < ApplicationController render json: @tags, status: 200 end + def tagsFilter + @tags = Tag.limit(100).order(quantity: :desc) + render json: @tags, status: 200 + end + end diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index cd43834..ac68ee4 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -19,7 +19,7 @@ class TracksController < ApplicationController when :tag, :channel, :user query.concat" #{filter}s.name='#{param}'" when :date - query.concat(" irc_posts.posted_at='#{param}'") + query.concat(" date(irc_posts.posted_at)='#{param}'") end end end @@ -51,7 +51,13 @@ class TracksController < ApplicationController def filtersOptimized( *filters ) condition = filterCondition( filters ) query = filterQuery( filters ) - @tracks = Track.joins(query).where(condition).page params[:page] + + + if [:channel, :user, :date].any? {|param| params.has_key? param} + @tracks = Track.joins(query).where(condition).group(:track_id).page params[:page] + else + @tracks = Track.joins(query).where(condition).page params[:page] + end end def index -- GitLab