Commit b59af7a5 authored by Andrea Ruggiero's avatar Andrea Ruggiero
Browse files

Improve performance

parent f02bb24d
Pipeline #1558 failed with stage
in 0 seconds
......@@ -7,19 +7,25 @@ class PlaceRepository extends BaseRepository
protected $table = 'places';
protected $all = null;
protected $by_id = [];
public function getById($id) {
if (isset($this->by_id[$id])) return $this->by_id[$id];
if ($this->all !== null) {
foreach ($this->all as $place) {
if ($place->place_id === $id) return $place;
if ($place->place_id === $id) {
$this->by_id[$id] = $place;
return $place;
}
}
}
return $this->db()->where('place_id', $id)->first();
$this->by_id[$id] = $this->db()->where('place_id', $id)->first();
return $this->by_id[$id];
}
public function all() {
if ($this->all === null) {
$all = $this->db()->table($this->table)->get();
$this->all = $this->db()->table($this->table)->get();
}
return $this->all;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment