| @@ -12,8 +12,10 @@ | ||
| 12 | 12 | protected $table = 'fcal_calendars'; |
| 13 | 13 | |
| 14 | 14 | protected $guarded = ['id']; |
| 15 | 15 | |
| 16 | + protected $metaCache = []; | |
| 17 | + | |
| 16 | 18 | protected $fillable = [ |
| 17 | 19 | 'hash', |
| 18 | 20 | 'user_id', |
| 19 | 21 | 'account_id', |
| @@ -170,13 +172,24 @@ | ||
| 170 | 172 | } |
| 171 | 173 | |
| 172 | 174 | public function getMeta($key, $default = null) |
| 173 | 175 | { |
| 174 | - $meta = Meta::where('object_type', 'Calendar') | |
| 175 | - ->where('object_id', $this->id) | |
| 176 | - ->where('key', $key) | |
| 177 | - ->first(); | |
| 176 | + if ($this->relationLoaded('metas')) { | |
| 177 | + $meta = $this->metas->firstWhere('key', $key); | |
| 178 | + return $meta ? $meta->value : $default; | |
| 179 | + } | |
| 178 | 180 | |
| 181 | + if (array_key_exists($key, $this->metaCache)) { | |
| 182 | + $meta = $this->metaCache[$key]; | |
| 183 | + } else { | |
| 184 | + $meta = Meta::where('object_type', 'Calendar') | |
| 185 | + ->where('object_id', $this->id) | |
| 186 | + ->where('key', $key) | |
| 187 | + ->first(); | |
| 188 | + | |
| 189 | + $this->metaCache[$key] = $meta; | |
| 190 | + } | |
| 191 | + | |
| 179 | 192 | if (!$meta) { |
| 180 | 193 | return $default; |
| 181 | 194 | } |
| 182 | 195 | |
| @@ -201,8 +214,10 @@ | ||
| 201 | 214 | 'value' => $value |
| 202 | 215 | ]); |
| 203 | 216 | } |
| 204 | 217 | |
| 218 | + $this->metaCache[$key] = $exist; | |
| 219 | + | |
| 205 | 220 | return $exist; |
| 206 | 221 | } |
| 207 | 222 | |
| 208 | 223 | public function getLandingPageUrl($isForce = false) |
| @@ -244,9 +259,9 @@ | ||
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | public static function getAllHosts() |
| 247 | 262 | { |
| 248 | - $calendars = self::with(['user']) | |
| 263 | + $calendars = self::with(['user', 'metas']) | |
| 249 | 264 | ->where('type', 'simple') |
| 250 | 265 | ->get(); |
| 251 | 266 | |
| 252 | 267 | $deletedUser = __('Deleted User', 'fluent-booking'); |