From b8b8aa50e17b7932b98e6f8cd3538e91ae9f23cc Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Wed, 20 Sep 2023 03:37:08 -0400 Subject: [PATCH] User primary key as index for online sessions --- classes/erlhcoreclassmodelesonlinesession.php | 12 +++--------- classes/lhelasticsearchindex.php | 5 +++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/classes/erlhcoreclassmodelesonlinesession.php b/classes/erlhcoreclassmodelesonlinesession.php index 0269643..f8dbb6c 100644 --- a/classes/erlhcoreclassmodelesonlinesession.php +++ b/classes/erlhcoreclassmodelesonlinesession.php @@ -24,21 +24,15 @@ public function __get($var) case 'time_front': $this->time_front = date('Ymd') == date('Ymd', $this->time / 1000) ? date(erLhcoreClassModule::$dateHourFormat, $this->time / 1000) : date(erLhcoreClassModule::$dateDateHourFormat, $this->time / 1000); return $this->time_front; - ; - break; - + case 'lactivity_front': $this->lactivity_front = date('Ymd') == date('Ymd', $this->lactivity / 1000) ? date(erLhcoreClassModule::$dateHourFormat, $this->lactivity / 1000) : date(erLhcoreClassModule::$dateDateHourFormat, $this->lactivity / 1000); return $this->lactivity_front; - ; - break; - + case 'duration_front': $this->duration_front = erLhcoreClassChat::formatSeconds($this->duration); return $this->duration_front; - ; - break; - + default: break; } diff --git a/classes/lhelasticsearchindex.php b/classes/lhelasticsearchindex.php index 526aa68..474051e 100644 --- a/classes/lhelasticsearchindex.php +++ b/classes/lhelasticsearchindex.php @@ -272,7 +272,7 @@ public static function indexOs($params) } $sparams = array(); - $sparams['body']['query']['bool']['must'][]['terms']['os_id'] = array_keys($params['items']); + $sparams['body']['query']['bool']['must'][]['terms']['_id'] = array_keys($params['items']); $sparams['limit'] = 1000; $documents = erLhcoreClassModelESOnlineSession::getList($sparams, array('date_index' => array('gte' => min($dateRange), 'lte' => max($dateRange)))); @@ -293,6 +293,7 @@ public static function indexOs($params) $osLog = $documentsReindexed[$keyValue]; } else { $osLog = new erLhcoreClassModelESOnlineSession(); + $osLog->id = $item->id; $osLog->user_id = $item->user_id; $osLog->os_id = $item->id; $osLog->time = $item->time * 1000; @@ -318,7 +319,7 @@ public static function indexOs($params) $objectsSave[$indexSave][] = $osLog; } - erLhcoreClassModelESOnlineSession::bulkSave($objectsSave, array('custom_index' => true)); + erLhcoreClassModelESOnlineSession::bulkSave($objectsSave, array('custom_index' => true, 'ignore_id' => true)); } public static function indexChatDelay($params)