Commit 001bbf84 authored by Andrea Ruggiero's avatar Andrea Ruggiero
Browse files

Improve performance

parent ae1ee41a
Pipeline #1562 failed with stage
in 0 seconds
......@@ -3,17 +3,31 @@
namespace App\Repositories;
use Illuminate\Database\DatabaseManager;
class EventRepository extends BaseRepository
protected $table = 'events';
protected $cache = [];
public function get($id) {
return $this->db()->where('event_id', $id)->first();
public function __construct(DatabaseManager $db) {
if (file_exists('cache.json'))
$this->cache = json_decode(file_get_contents('cache.json'), true);
public function getSimilarEvents($event) {
return $this->db()->where('title', $event->title)->where('date', $event->date)->where('start', $event->start)->where('end', $event->end)->select('place_id', 'event_id')->get();
if (!isset($this->cache[$event->event_id])) {
$this->cache[$event->event_id] = $this->db()->where('title', $event->title)->where('date', $event->date)->where('start', $event->start)->where('end', $event->end)->select('place_id', 'event_id')->get();
file_put_contents('cache.json', json_encode($this->cache));
return $this->cache[$event->event_id];
\ No newline at end of file
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