mirror of
				https://github.com/scinote-eln/scinote-web.git
				synced 2025-11-01 00:56:05 +08:00 
			
		
		
		
	Improve speed of protocol templates table loading [SCI-8553] (#5509)
This commit is contained in:
		
							parent
							
								
									08c9777b2a
								
							
						
					
					
						commit
						a0616adf17
					
				
					 1 changed files with 10 additions and 10 deletions
				
			
		|  | @ -216,16 +216,16 @@ class Protocol < ApplicationRecord | ||||||
|   def self.viewable_by_user(user, teams) |   def self.viewable_by_user(user, teams) | ||||||
|     # Team owners see all protocol templates in the team |     # Team owners see all protocol templates in the team | ||||||
|     owner_role = UserRole.find_predefined_owner_role |     owner_role = UserRole.find_predefined_owner_role | ||||||
|     protocols = Protocol.left_outer_joins(:team, user_assignments: :user_role) |     protocols = Protocol.where(team: teams) | ||||||
|                         .joins("LEFT OUTER JOIN user_assignments team_user_assignments " \ |                         .where(protocol_type: REPOSITORY_TYPES) | ||||||
|  |     viewable_as_team_owner = protocols.joins("INNER JOIN user_assignments team_user_assignments " \ | ||||||
|                                              "ON team_user_assignments.assignable_type = 'Team' " \ |                                              "ON team_user_assignments.assignable_type = 'Team' " \ | ||||||
|                                "AND team_user_assignments.assignable_id = team.id") |                                              "AND team_user_assignments.assignable_id = protocols.team_id") | ||||||
|                         .where(team: teams) |                                       .where(team_user_assignments: { user_id: user, user_role_id: owner_role }) | ||||||
|     protocols |                                       .select(:id) | ||||||
|       .where( |     viewable_as_assigned = protocols.with_granted_permissions(user, ProtocolPermissions::READ).select(:id) | ||||||
|         protocol_type: REPOSITORY_TYPES, team: { team_user_assignments: { user_id: user, user_role_id: owner_role } } | 
 | ||||||
|       ) |     where('protocols.id IN ((?) UNION (?))', viewable_as_team_owner, viewable_as_assigned) | ||||||
|       .or(protocols.with_granted_permissions(user, ProtocolPermissions::READ)).distinct |  | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def self.filter_by_teams(teams = []) |   def self.filter_by_teams(teams = []) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue