feat: ✨ add post access usage metrics
This commit is contained in:
parent
eb87a78625
commit
94b65aec8c
3 changed files with 161 additions and 74 deletions
|
@ -103,6 +103,47 @@ class MySQLAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
function log_post_access($post_path, $agent, $time) {
|
||||
$qry = "
|
||||
INSERT INTO path_access_counts
|
||||
(post_path, agent,
|
||||
path_access_count,
|
||||
path_processing_time)
|
||||
VALUES ( ?, ?, 1, ? ) AS new
|
||||
ON DUPLICATE KEY
|
||||
UPDATE path_access_count=path_access_counts.path_access_count+1,
|
||||
path_processing_time=path_access_counts.path_processing_time+new.path_processing_time;
|
||||
";
|
||||
|
||||
$this->_exec($qry, "ssd", $post_path, $agent, $time);
|
||||
}
|
||||
|
||||
function get_post_access_counters() {
|
||||
$qry = "
|
||||
SELECT post_path, agent, path_access_count, path_processing_time
|
||||
FROM path_access_counts
|
||||
WHERE path_last_access_time > ( CURRENT_TIMESTAMP - INTERVAL 10 MINUTE );
|
||||
";
|
||||
|
||||
$data = $this->_exec($qry, "")->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$out_data = [];
|
||||
|
||||
foreach($data AS $post_data) {
|
||||
$path = $post_data['post_path'];
|
||||
|
||||
$agent_data = ($out_data[$path] ?? []);
|
||||
|
||||
$agent_data[$post_data['agent']] = [
|
||||
'count' => $post_data['path_access_count'],
|
||||
'time' => round($post_data['path_processing_time'], 6)
|
||||
];
|
||||
|
||||
$out_data[$path] = $agent_data;
|
||||
}
|
||||
|
||||
return $out_data;
|
||||
}
|
||||
function update_or_create_post($post_path, $post_metadata, $post_content) {
|
||||
$post_path = $this->_sanitize_path($post_path);
|
||||
$path_depth = substr_count($post_path, "/");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue