Skip to content
Extraits de code Groupes Projets
Valider 0bbdc1b9 rédigé par Sybil's avatar Sybil
Parcourir les fichiers

- Seeds compute the quantity of tracks per user ...

- Order user, tag, channel by their size.
parent b61df3cc
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class ChannelsController < ApplicationController class ChannelsController < ApplicationController
def index def index
@channels = Channel.all.order(quantity: :desc)
render json: @channels, status: 200 render json: @channels, status: 200
end end
end end
class TagsController < ApplicationController class TagsController < ApplicationController
def index def index
@tags = Tag.all.order(quantity: :desc)
render json: @tags, status: 200 render json: @tags, status: 200
end end
......
...@@ -11,9 +11,15 @@ class TracksController < ApplicationController ...@@ -11,9 +11,15 @@ class TracksController < ApplicationController
#@tracks = Track.includes(irc_posts: [:channel, :user], tag_assignations: :tag).all #includes(irc_posts: [{ :channels, :users}]) #includes(:channels,:tags,:users) #@tracks = Track.includes(irc_posts: [:channel, :user], tag_assignations: :tag).all #includes(irc_posts: [{ :channels, :users}]) #includes(:channels,:tags,:users)
#t = Track.all.joins('inner join irc_posts i ON tracks.track_id = i.track_id inner join channels c on i.channel_id = c.channel_id inner join gnations ti on tracks.track_id = ti.track_id inner join tags ta on ta.tag_id = ti.tag_id').select('tracks.name as t_name, u.name as u_name, c.name as c_name, ta.name as t_name') #t = Track.all.joins('inner join irc_posts i ON tracks.track_id = i.track_id inner join channels c on i.channel_id = c.channel_id inner join gnations ti on tracks.track_id = ti.track_id inner join tags ta on ta.tag_id = ti.tag_id').select('tracks.name as t_name, u.name as u_name, c.name as c_name, ta.name as t_name')
#t.first.c_name #t.first.c_name
@tracks = Track.page params[:page] @tracks = Track.includes(:tags).page params[:page]
filters :tag, :channel, :user filters :tag, :channel, :user
render json: @tracks, status: 200 render json: @tracks,
status: 200,
meta: {
current_page: @tracks.current_page,
per_page: @tracks.default_per_page,
total_pages: @tracks.num_pages
}
end end
def show def show
......
class UsersController < ApplicationController
def index
@users = User.all.order(quantity: :desc)
render json: @users, status: 200
end
end
class Track < ActiveRecord::Base class Track < ActiveRecord::Base
paginates_per 50 paginates_per 51
#default_scope includes(:channels,:users,:tags) #default_scope includes(:channels,:users,:tags)
has_many :irc_posts has_many :irc_posts
......
class ChannelSerializer < ActiveModel::Serializer class ChannelSerializer < ActiveModel::Serializer
attributes :id, :name attributes :id, :name, :quantity
#has_many :tracks #has_many :tracks
#has_many :users #has_many :users
......
class TagSerializer < ActiveModel::Serializer class TagSerializer < ActiveModel::Serializer
attributes :id, :name attributes :id, :name, :quantity
#belongs_to :track #belongs_to :track
end end
class TrackSerializer < ActiveModel::Serializer class TrackSerializer < ActiveModel::Serializer
attributes :id, :name, :url, :provider, :author, :channel attributes :id, :name, :url, :provider, :author, :channel
embed :ids, include: true #embed :ids, include: true
has_many :channels #has_many :channels
has_many :tags has_many :tags, embed: :ids, include: true
has_many :users #has_many :users
end end
class UserSerializer < ActiveModel::Serializer class UserSerializer < ActiveModel::Serializer
attributes :id, :name attributes :id, :name, :quantity
#belongs_to :track #belongs_to :track
end end
...@@ -5,9 +5,9 @@ Rails.application.routes.draw do ...@@ -5,9 +5,9 @@ Rails.application.routes.draw do
concern :tracks do concern :tracks do
resources :tracks, only: [:index] resources :tracks, only: [:index]
end end
#resources :tags, concerns: :tracks, only: [:index, :show] resources :tags, concerns: :tracks, only: [:index, :show]
#resources :channels, concerns: :tracks, only: [:index, :show] resources :channels, concerns: :tracks, only: [:index, :show]
#resources :users, concerns: :tracks, only: [:index, :show] resources :users, concerns: :tracks, only: [:index, :show]
resources :tracks, only: [:index, :show] resources :tracks, only: [:index, :show]
root to: 'tracks#index' root to: 'tracks#index'
......
...@@ -15,13 +15,16 @@ OldDatabase::PlaybotChan.find_each do |p_chan| ...@@ -15,13 +15,16 @@ OldDatabase::PlaybotChan.find_each do |p_chan|
end end
user = User.find_or_create_by(name: p_chan.sender_irc) user = User.find_or_create_by(name: p_chan.sender_irc)
user.increment!(:quantity)
channel = Channel.find_or_create_by(name: p_chan.chan) channel = Channel.find_or_create_by(name: p_chan.chan)
channel.increment!(:quantity)
IrcPost.create(track_id: track.id, channel_id: channel.id, user_id: user.id, posted_at: p_chan.date) IrcPost.create(track_id: track.id, channel_id: channel.id, user_id: user.id, posted_at: p_chan.date)
end end
OldDatabase::PlaybotTag.all.each do |p_tag| OldDatabase::PlaybotTag.all.each do |p_tag|
tag = Tag.find_or_create_by(name: p_tag.tag) tag = Tag.find_or_create_by(name: p_tag.tag)
tag.increment!(:quantity)
TagAssignation.create(track_id: p_tag.id, tag_id: tag.id) TagAssignation.create(track_id: p_tag.id, tag_id: tag.id)
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter