mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
cut contributor queries in half
This commit is contained in:
parent
2fd6af8ef5
commit
79e14e764f
@ -1,6 +1,9 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
before_action :cache_most_used_page_information
|
||||
|
||||
# todo name all these methods
|
||||
before_action do
|
||||
if params[:universe].present? && user_signed_in?
|
||||
if params[:universe] == 'all'
|
||||
@ -28,14 +31,17 @@ class ApplicationController < ActionController::Base
|
||||
@page_description ||= 'Notebook.ai is a set of tools for writers, game designers, and roleplayers to create magnificent universes — and everything within them.'
|
||||
end
|
||||
|
||||
before_action do
|
||||
|
||||
def content_type_from_controller(content_controller_name)
|
||||
content_controller_name.to_s.chomp('Controller').singularize.constantize
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cache_most_used_page_information
|
||||
@activated_content_types = (
|
||||
Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order
|
||||
current_user.user_content_type_activators.pluck(:content_type)
|
||||
)
|
||||
end
|
||||
|
||||
def content_type_from_controller(content_controller_name)
|
||||
content_controller_name.to_s.chomp('Controller').singularize.constantize
|
||||
end
|
||||
end
|
||||
|
||||
@ -38,10 +38,9 @@ class User < ApplicationRecord
|
||||
def contributable_universes
|
||||
@user_contributable_universes ||= begin
|
||||
# todo email confirmation needs to happy for data safety / privacy (only verified emails)
|
||||
contributor_by_email = Contributor.where(email: self.email).pluck(:universe_id)
|
||||
contributor_by_user = Contributor.where(user: self).pluck(:universe_id)
|
||||
contributor_ids = Contributor.where('email = ? OR user_id = ?', self.email, self.id).pluck(:universe_id)
|
||||
|
||||
Universe.where(id: contributor_by_email + contributor_by_user)
|
||||
Universe.where(id: contributor_ids)
|
||||
end
|
||||
end
|
||||
#TODO: rename this to #{content_type}_shared_with_me and only return contributable content that others own
|
||||
|
||||
Loading…
Reference in New Issue
Block a user