Skip to content

Commit 83eb947

Browse files
committed
Optimize ilSessionStatistics raw data aggregation
1 parent be258ac commit 83eb947

1 file changed

Lines changed: 65 additions & 24 deletions

File tree

components/ILIAS/Authentication/classes/class.ilSessionStatistics.php

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,73 @@ public static function aggretateRaw(int $a_now): void
246246
}
247247

248248
$slot = self::createNewAggregationSlot($a_now);
249+
$prepared_statement = self::getAggregatedRawDataPreparedStatement();
250+
$raw_data = [];
249251
while (is_array($slot)) {
250-
self::aggregateRawHelper($slot[0], $slot[1]);
252+
$raw_data[] = self::aggregateRawHelper($slot[0], $slot[1]);
251253
$slot = self::createNewAggregationSlot($a_now);
252254
}
253255

256+
if ($raw_data !== []) {
257+
global $DIC;
258+
$DIC->database()->executeMultiple($prepared_statement, $raw_data);
259+
}
260+
254261
// #12728
255262
self::deleteAggregatedRaw($a_now);
256263
}
257264

265+
protected static function getAggregatedRawDataPreparedStatement(): ilDBStatement
266+
{
267+
global $DIC;
268+
return $DIC->database()->prepareManip(
269+
"UPDATE usr_session_stats "
270+
. "SET active_min = ?, "
271+
. "active_max = ?, "
272+
. "active_avg = ?, "
273+
. "active_end = ?, "
274+
. "opened = ?, "
275+
. "closed_manual = ?, "
276+
. "closed_expire = ?, "
277+
. "closed_login = ?, "
278+
. "closed_misc = ? "
279+
. "WHERE slot_begin = ? AND slot_end = ?",
280+
[
281+
ilDBConstants::T_INTEGER,
282+
ilDBConstants::T_INTEGER,
283+
ilDBConstants::T_INTEGER,
284+
ilDBConstants::T_INTEGER,
285+
ilDBConstants::T_INTEGER,
286+
ilDBConstants::T_INTEGER,
287+
ilDBConstants::T_INTEGER,
288+
ilDBConstants::T_INTEGER,
289+
ilDBConstants::T_INTEGER,
290+
ilDBConstants::T_INTEGER,
291+
ilDBConstants::T_INTEGER
292+
]
293+
);
294+
}
295+
258296
/**
259297
* Aggregate statistics data for one slot
260-
*
298+
* @return array{
299+
* active_min: int,
300+
* active_max: int,
301+
* active_avg: float|int,
302+
* active_end: int,
303+
* opened: int,
304+
* closed_manual: int,
305+
* closed_expire: int,
306+
* closed_login: int,
307+
* closed_misc: int,
308+
* slot_begin: int,
309+
* slot_end: int
310+
* }
261311
*/
262-
public static function aggregateRawHelper(int $a_begin, int $a_end): void
312+
public static function aggregateRawHelper(int $a_begin, int $a_end): array
263313
{
264314
global $DIC;
265315

266-
$ilDB = $DIC['ilDB'];
267-
268316
// "relevant" closing types
269317
$separate_closed = [
270318
ilSession::SESSION_CLOSE_USER,
@@ -354,26 +402,19 @@ public static function aggregateRawHelper(int $a_begin, int $a_end): void
354402
}
355403
unset($events);
356404

357-
// save aggregated data
358-
$fields = [
359-
'active_min' => ['integer', $active_min],
360-
'active_max' => ['integer', $active_max],
361-
'active_avg' => ['integer', $active_avg],
362-
'active_end' => ['integer', $active_end],
363-
'opened' => ['integer', $opened_counter],
364-
'closed_manual' => ['integer', (int) ($closed_counter[ilSession::SESSION_CLOSE_USER] ?? 0)],
365-
'closed_expire' => ['integer', (int) ($closed_counter[ilSession::SESSION_CLOSE_EXPIRE] ?? 0)],
366-
'closed_login' => ['integer', (int) ($closed_counter[ilSession::SESSION_CLOSE_LOGIN] ?? 0)],
367-
'closed_misc' => ['integer', (int) ($closed_counter[0] ?? 0)],
405+
return [
406+
'active_min' => $active_min,
407+
'active_max' => $active_max,
408+
'active_avg' => $active_avg,
409+
'active_end' => $active_end,
410+
'opened' => $opened_counter,
411+
'closed_manual' => (int) ($closed_counter[ilSession::SESSION_CLOSE_USER] ?? 0),
412+
'closed_expire' => (int) ($closed_counter[ilSession::SESSION_CLOSE_EXPIRE] ?? 0),
413+
'closed_login' => (int) ($closed_counter[ilSession::SESSION_CLOSE_LOGIN] ?? 0),
414+
'closed_misc' => (int) ($closed_counter[0] ?? 0),
415+
'slot_begin' => $a_begin,
416+
'slot_end' => $a_end,
368417
];
369-
$ilDB->update(
370-
'usr_session_stats',
371-
$fields,
372-
[
373-
'slot_begin' => ['integer', $a_begin],
374-
'slot_end' => ['integer', $a_end]
375-
]
376-
);
377418
}
378419

379420
/**

0 commit comments

Comments
 (0)