diff options
| author | Malte Franken <mail@malte-franken.de> | 2015-08-08 02:46:19 +1000 |
|---|---|---|
| committer | Malte Franken <mail@malte-franken.de> | 2015-08-08 02:46:19 +1000 |
| commit | 0be4b89c07b5f0e61d6e312d94ab8ec899a86f6d (patch) | |
| tree | 8f6613333ecaf884d75863a382b37fe44f891d09 /app/Functions | |
| parent | 7837f0eb5cb0cc4ed55fc914c9c26eb902fca78e (diff) | |
| download | webtrees-0be4b89c07b5f0e61d6e312d94ab8ec899a86f6d.tar.gz webtrees-0be4b89c07b5f0e61d6e312d94ab8ec899a86f6d.tar.bz2 webtrees-0be4b89c07b5f0e61d6e312d94ab8ec899a86f6d.zip | |
Using a local cache for resolved relationship names to accelerate the computation of very complex relationships
Diffstat (limited to 'app/Functions')
| -rw-r--r-- | app/Functions/Functions.php | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/Functions/Functions.php b/app/Functions/Functions.php index 741e2daa29..5769ffa03b 100644 --- a/app/Functions/Functions.php +++ b/app/Functions/Functions.php @@ -666,6 +666,9 @@ class Functions { } } + // Cache for generic relationships determination + protected static $relationshipsCache = array(); + /** * Convert a relationship path into a relationship name. * @@ -2156,6 +2159,10 @@ class Functions { // Split the relationship into sub-relationships, e.g., third-cousin’s great-uncle. // Try splitting at every point, and choose the path with the shorted translated name. + // But before starting to recursively go through all combinations, do a cache look-up + if (array_key_exists($path, self::$relationshipsCache)) { + return self::$relationshipsCache[$path]; + } $relationship = null; $path1 = substr($path, 0, 3); @@ -2173,6 +2180,8 @@ class Functions { $path1 .= substr($path2, 0, 3); $path2 = substr($path2, 3); } + // and store the result in the cache + self::$relationshipsCache[$path] = $relationship; return $relationship; } |
