]> git.mxchange.org Git - friendica.git/commitdiff
plugin optimisation - don't loop through every single plugin callback for every hook...
authorfriendica <info@friendica.com>
Wed, 20 Jun 2012 01:26:40 +0000 (18:26 -0700)
committerfriendica <info@friendica.com>
Wed, 20 Jun 2012 01:26:40 +0000 (18:26 -0700)
boot.php
include/plugin.php

index 78e1dac6a7cc2f3139ca4811e333c392670750a3..76cf8af57969685ea4797445c8457def7b63d301 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -77,14 +77,6 @@ define ( 'CONTACT_IS_SHARING',  2);
 define ( 'CONTACT_IS_FRIEND',   3);
 
 
-/**
- * Hook array order
- */
-
-define ( 'HOOK_HOOK',      0);
-define ( 'HOOK_FILE',      1);
-define ( 'HOOK_FUNCTION',  2);
-
 /**
  * DB update return values
  */
index ae8eee78a429cd38c1fc7b1a00dd07041ce7c37f..c6b61ae6e92fe45a54920cfa5faf672a34c2e95b 100644 (file)
@@ -148,7 +148,9 @@ function load_hooks() {
        $r = q("SELECT * FROM `hook` WHERE 1");
        if(count($r)) {
                foreach($r as $rr) {
-                       $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
+                       if(! array_key_exists($rr['hook'],$a->hooks))
+                               $a->hooks[$rr['hook']] = array();
+                       $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
                }
        }
 }}
@@ -158,25 +160,24 @@ if(! function_exists('call_hooks')) {
 function call_hooks($name, &$data = null) {
        $a = get_app();
 
-       if(count($a->hooks)) {
-               foreach($a->hooks as $hook) {
-                       if($hook[HOOK_HOOK] === $name) {
-                               @include_once($hook[HOOK_FILE]);
-                               if(function_exists($hook[HOOK_FUNCTION])) {
-                                       $func = $hook[HOOK_FUNCTION];
-                                       $func($a,$data);
-                               }
-                               else {
-                                       // remove orphan hooks
-                                       q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
-                                               dbesc($hook[HOOK_HOOK]),
-                                               dbesc($hook[HOOK_FILE]),
-                                               dbesc($hook[HOOK_FUNCTION])
-                                       );
-                               }
+       if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
+               foreach($a->hooks[$name] as $hook) {
+                       @include_once($hook[0]);
+                       if(function_exists($hook[1])) {
+                               $func = $hook[1];
+                               $func($a,$data);
+                       }
+                       else {
+                               // remove orphan hooks
+                               q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
+                                       dbesc($name),
+                                       dbesc($hook[0]),
+                                       dbesc($hook[1])
+                               );
                        }
                }
        }
+
 }}