diff --git a/app/controllers/admin/researchs_controller.rb b/app/controllers/admin/researchs_controller.rb index b04fcc3..d591771 100644 --- a/app/controllers/admin/researchs_controller.rb +++ b/app/controllers/admin/researchs_controller.rb @@ -10,7 +10,7 @@ class Admin::ResearchsController < OrbitMemberController before_action :allow_admin_only, :only => [:index, :setting] def index - @researchs = Research.order_by(:year=>'desc').page(params[:page]).per(10) + @researchs = Research.sort_year_date.page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_researches_controller.rb b/app/controllers/personal_researches_controller.rb index 8fa4b38..fb506b4 100644 --- a/app/controllers/personal_researches_controller.rb +++ b/app/controllers/personal_researches_controller.rb @@ -1,6 +1,6 @@ class PersonalResearchesController < ApplicationController def index - researchs = Research.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) + researchs = Research.sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) research_list = researchs.collect do |research| member = research.member_profile path = OrbitHelper.url_to_plugin_show(member.to_param, 'member') rescue '#' diff --git a/app/models/research.rb b/app/models/research.rb index 1d7b7e3..4e60417 100644 --- a/app/models/research.rb +++ b/app/models/research.rb @@ -30,7 +30,9 @@ class Research before_validation :add_http - scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc") } + index({year: -1, publish_date: -1, _id: -1}, { unique: false, background: false }) + scope :sort_year_date, ->{ order_by(:year => "desc", :publish_date => "desc", :id => "desc") } + scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publish_date => "desc", :id => "desc") } def get_plugin_data(fields_to_show) plugin_datas = [] @@ -69,7 +71,7 @@ class Research fields_to_show = fields_to_show - fields_to_remove - plugin_datas = datas.sort_for_frontend.collect.with_index do |p, index| + plugin_datas = datas.sort_for_frontend.collect.with_index do |p, idx| pd_data = [] fields_to_show.collect do |t| @@ -85,7 +87,7 @@ class Research { "pd_datas" => pd_data, "type-sort" => (p.research_category.sort_position.to_i rescue -1), - "sort-index" => index + "sort-index" => idx } end diff --git a/app/views/plugin/personal_research/_profile.html.erb b/app/views/plugin/personal_research/_profile.html.erb index 6c08464..fda551c 100644 --- a/app/views/plugin/personal_research/_profile.html.erb +++ b/app/views/plugin/personal_research/_profile.html.erb @@ -7,9 +7,9 @@ <% if has_access? - @researchs = Research.where(member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @researchs = Research.where(member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) else - @researchs = Research.where(is_hidden: false, member_profile_id: @member.id).desc(:year).page(params[:page]).per(10) + @researchs = Research.where(is_hidden: false, member_profile_id: @member.id).sort_year_date.page(params[:page]).per(10) end %>