diff --git a/app/controllers/admin/labs_controller.rb b/app/controllers/admin/labs_controller.rb index 75985f0..b5b4c7f 100644 --- a/app/controllers/admin/labs_controller.rb +++ b/app/controllers/admin/labs_controller.rb @@ -10,7 +10,7 @@ class Admin::LabsController < OrbitMemberController before_action :allow_admin_only, :only => [:index, :setting] def index - @labs = Lab.order_by(:year=>'desc').page(params[:page]).per(10) + @labs = Lab.sort_year.page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_labs_controller.rb b/app/controllers/personal_labs_controller.rb index e9ef0a2..743e571 100644 --- a/app/controllers/personal_labs_controller.rb +++ b/app/controllers/personal_labs_controller.rb @@ -1,6 +1,6 @@ class PersonalLabsController < ApplicationController def index - labs = Lab.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + labs = Lab.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) lab_list = labs.collect do |lab| member = lab.member_profile path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#' diff --git a/app/models/lab.rb b/app/models/lab.rb index 8ddba7d..0ffd471 100644 --- a/app/models/lab.rb +++ b/app/models/lab.rb @@ -29,7 +29,9 @@ class Lab before_validation :add_http - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc") } + index({year: -1, _id: -1}, { unique: false, background: false }) + scope :sort_year, ->{ order_by(:year => "desc", :id=>"desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :id=>"desc") } def get_plugin_data(fields_to_show) plugin_datas = [] diff --git a/app/views/plugin/personal_lab/_profile.html.erb b/app/views/plugin/personal_lab/_profile.html.erb index 64518d8..27803c8 100644 --- a/app/views/plugin/personal_lab/_profile.html.erb +++ b/app/views/plugin/personal_lab/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @labs = Lab.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @labs = Lab.where(member_profile_id: @member.id).sort_year.page(params[:page]).per(10) else - @labs = Lab.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @labs = Lab.where(is_hidden: false, member_profile_id: @member.id).sort_year.page(params[:page]).per(10) end %>