From 420ec011a17a62680df99d9624353e48fe58a8f8 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 13 Sep 2023 19:35:22 +0200 Subject: [PATCH] wait #6274 @0.25 --- src/Links/CustomLink.php | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/Links/CustomLink.php b/src/Links/CustomLink.php index d6b5205..7e62d46 100644 --- a/src/Links/CustomLink.php +++ b/src/Links/CustomLink.php @@ -8,9 +8,12 @@ class CustomLink extends NormalLink { protected $role = 'link'; + protected static $_all = []; + public function getURL() { - return static::_getURL($this->to); + $res = static::_getURL($this->to); + return $res; } public function getTarget() @@ -39,25 +42,41 @@ class CustomLink extends NormalLink { $ref = str_replace('custom:', '', $ref); $e = explode(':', $ref, 2); - if (count($e) == 2 && $e[0] == $type) { + if (count($e) == 2) { $ref = $e[1]; $type = $e[0]; } $nospaceref = str_replace(' ', '', $ref); - $res = DB::table('fluidbook_reference_url')->where('type', $type)->whereIn('ref', [$ref, $nospaceref])->get(); - if ($res->count() > 0) { - $url = $res->get('url'); - if (!$url || $url === '-') { - return $default; - } - return $url; + $all = self::getAllURLOf($type); + if (isset($all[$ref])) { + $res = $all[$ref]; + } else if (isset($all[$nospaceref])) { + $res = $all[$nospaceref]; + } else { + return $default; } - return $default; + + if (!$res || $res === '-') { + return $default; + } + return $res; } public function ignore() { return parent::ignore() || !$this->getURL() || $this->getURL() === '-'; } + + protected static function getAllURLOf($type) + { + if (!isset(self::$_all[$type])) { + self::$_all[$type] = []; + $res = DB::table('fluidbook_reference_url')->where('type', $type)->get(['url', 'ref']); + foreach ($res as $item) { + self::$_all[$type][$item->ref] = $item->url; + } + } + return self::$_all[$type]; + } } -- 2.39.5