Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/Database/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@

use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use Helioviewer\Api\Sentry\Sentry;

class Database_Statistics {

private $_dbConnection;

/**
* Report a database failure to Sentry tagged as "Database Error".
*/
private function _reportDatabaseError(\Throwable $e): void {
Sentry::setTag('error_type', 'Database Error');
Sentry::capture($e);
}

/**
* Constructor
*
Expand Down Expand Up @@ -94,6 +103,7 @@ public function log($action) {
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand All @@ -111,8 +121,6 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) {
$sql = sprintf(
"INSERT INTO movies_jpx "
. "SET "
. "id " . " = NULL, "
. "timestamp " . " = NULL, "
. "reqStartDate " . " = '%s', "
. "reqEndDate " . " = '%s', "
. "sourceId " . " = %d;",
Expand All @@ -124,6 +132,7 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) {
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down Expand Up @@ -155,6 +164,8 @@ public function logRedis($action, $redis = null){
$redis->incr($key);
}catch(Exception $e){
//continue gracefully if redis statistics logging fails
Sentry::setTag('error_type', 'Redis Error');
Sentry::capture($e);
}
}

Expand Down Expand Up @@ -204,7 +215,7 @@ public function saveStatisticsFromRedis($redis){
}
}
catch (Exception $e) {

$this->_reportDatabaseError($e);
}
}

Expand Down Expand Up @@ -253,7 +264,7 @@ public function saveRateLimitExceededFromRedis($redis){
}
}
catch (Exception $e) {

$this->_reportDatabaseError($e);
}
}

Expand Down Expand Up @@ -481,6 +492,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down Expand Up @@ -526,6 +538,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand All @@ -552,6 +565,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down Expand Up @@ -600,6 +614,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$resultScreenshots = $this->_dbConnection->query($sqlScreenshots);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down Expand Up @@ -651,6 +666,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$resultScreenshots = $this->_dbConnection->query($sqlScreenshots);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down Expand Up @@ -718,6 +734,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu
$result = $this->_dbConnection->query($sql);
}
catch (Exception $e) {
$this->_reportDatabaseError($e);
return false;
}

Expand Down
Loading