]> source.dussan.org Git - nextcloud-server.git/commitdiff
Cache results of available languages
authorLukas Reschke <lukas@owncloud.com>
Wed, 26 Nov 2014 23:01:55 +0000 (00:01 +0100)
committerLukas Reschke <lukas@owncloud.com>
Wed, 26 Nov 2014 23:01:55 +0000 (00:01 +0100)
This function is about 8 times calles for every single page call, when caching this variable I was able to gain a small performance improvement from 20,512 µs to 630 µs profiled with xhprof

Surely, this is no gigantic gain but if we would do that for every function out there...

lib/private/l10n.php

index afa066c30ef66a2b61088f3ee68e9df09f755039..bc4e53e975cf4d5fbadccbc0e32c09e7f3a710d8 100644 (file)
@@ -20,6 +20,7 @@ class OC_L10N implements \OCP\IL10N {
         * cache
         */
        protected static $cache = array();
+       protected static $availableLanguages = array();
 
        /**
         * The best language
@@ -468,6 +469,9 @@ class OC_L10N implements \OCP\IL10N {
         * @return array an array of available languages
         */
        public static function findAvailableLanguages($app=null) {
+               if(!empty(self::$availableLanguages)) {
+                       return self::$availableLanguages;
+               }
                $available=array('en');//english is always available
                $dir = self::findI18nDir($app);
                if(is_dir($dir)) {
@@ -479,6 +483,8 @@ class OC_L10N implements \OCP\IL10N {
                                }
                        }
                }
+
+               self::$availableLanguages = $available;
                return $available;
        }