Move loadCSSFile to a better location that isn't affected by caching (#146)
Jeremy D

Jeremy D commited on 2021-08-18 19:24:20
Showing 2 changed files, with 25 additions and 3 deletions.


Try to cache permission loading for better performance
... ...
@@ -1599,6 +1599,9 @@ function shd_init_actions(&$actionArray)
1599 1599
 	if (empty($modSettings['helpdesk_active']))
1600 1600
 		return;
1601 1601
 
1602
+	// Load some extra CSS
1603
+	loadCSSFile('helpdesk_icons.css', array('minimize' => empty($context['shd_developer_mode']), 'seed' => $context['shd_css_version']), 'helpdesk_icons');
1604
+
1602 1605
 	// Deal with SimpleDesk. If we're enabling HD only mode, rebuild everything, otherwise just add it to the array.
1603 1606
 	$actionArray['helpdesk'] = array('sd_source/SimpleDesk.php', 'shd_main');
1604 1607
 
... ...
@@ -1705,9 +1708,6 @@ function shd_main_menu(&$menu_buttons)
1705 1708
 	if (empty($modSettings['helpdesk_active']))
1706 1709
 		return;
1707 1710
 
1708
-	// Load some extra CSS
1709
-	loadCSSFile('helpdesk_icons.css', array('minimize' => empty($context['shd_developer_mode']), 'seed' => $context['shd_css_version']), 'helpdesk_icons');
1710
-
1711 1711
 	// Stuff we'll always do in SD if active
1712 1712
 	$helpdesk_admin = $context['user']['is_admin'] || shd_allowed_to('admin_helpdesk', 0);
1713 1713
 
... ...
@@ -581,6 +581,11 @@ function shd_members_allowed_to($permission, $dept = 0)
581 581
 {
582 582
 	global $smcFunc;
583 583
 
584
+	static $lookups = array();
585
+
586
+	if (isset($lookups[$permission], $lookups[$permission][$dept]))
587
+		return $lookups[$permission][$dept];
588
+
584 589
 	$member_groups = shd_groups_allowed_to($permission, $dept);
585 590
 
586 591
 	$request = $smcFunc['db_query']('', '
... ...
@@ -600,6 +605,12 @@ function shd_members_allowed_to($permission, $dept = 0)
600 605
 		$members[] = $row['id_member'];
601 606
 	$smcFunc['db_free_result']($request);
602 607
 
608
+	if (isset($lookups[$permission]))
609
+		$lookups[$permission] = array();
610
+
611
+	if (isset($lookups[$permission][$dept]))
612
+		$lookups[$permission][$dept] = $members;
613
+
603 614
 	return $members;
604 615
 }
605 616
 
... ...
@@ -615,6 +626,11 @@ function shd_groups_allowed_to($permission, $dept = 0)
615 626
 {
616 627
 	global $smcFunc, $context;
617 628
 
629
+	static $lookups = array();
630
+
631
+	if (isset($lookups[$permission], $lookups[$permission][$dept]))
632
+		return $lookups[$permission][$dept];
633
+
618 634
 	// Admins are allowed to do anything.
619 635
 	$member_groups = array(
620 636
 		'allowed' => array(1),
... ...
@@ -685,5 +701,11 @@ function shd_groups_allowed_to($permission, $dept = 0)
685 701
 	// 4. All done, just clear up groups and send 'em home
686 702
 	$member_groups['allowed'] = array_diff($member_groups['allowed'], array_diff($member_groups['denied'], array(1)));
687 703
 
704
+	if (isset($lookups[$permission]))
705
+		$lookups[$permission] = array();
706
+
707
+	if (isset($lookups[$permission][$dept]))
708
+		$lookups[$permission][$dept] = $member_groups;
709
+
688 710
 	return $member_groups;
689 711
 }
690 712
\ No newline at end of file
691 713