Fix bugs in performance improvement

This commit is contained in:
Starbeamrainbowlabs 2019-11-07 19:04:05 +00:00
parent c8174f47be
commit e52c136406
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 14 additions and 13 deletions

8
build
View file

@ -28,7 +28,7 @@ cache_dir="./.cache";
build_output_folder="./app"; build_output_folder="./app";
# Database settings for ssh port forwarding task # Database settings for ssh port forwarding task
database_host="aq.connectedhumber.org"; database_host="db.connectedhumber.org";
database_name="aq_db"; database_name="aq_db";
database_user="www-data"; database_user="www-data";
@ -37,7 +37,7 @@ min_npm_version_major="6";
# Deployment settings # Deployment settings
deploy_ssh_user="ci"; deploy_ssh_user="ci";
deploy_ssh_host="sensors.connectedhumber.org"; deploy_ssh_host="aq.connectedhumber.org";
deploy_ssh_port="22"; deploy_ssh_port="22";
deploy_root_dir="Air-Quality-Web"; deploy_root_dir="Air-Quality-Web";
@ -378,10 +378,6 @@ SFTPCOMMANDS
echo "ln -s \"../data\" \"${deploy_root_dir}/www-new/data\""; echo "ln -s \"../data\" \"${deploy_root_dir}/www-new/data\"";
if [ "${GIT_REF_NAME}" == "refs/heads/master" ]; then
echo "ln -s \"../../Air-Quality-Web-Beta/www/\" \"${deploy_root_dir}/www-new/beta\"";
fi
echo "mv \"${deploy_root_dir}/www\" \"${deploy_root_dir}/www-old\""; echo "mv \"${deploy_root_dir}/www\" \"${deploy_root_dir}/www-old\"";
echo "mv \"${deploy_root_dir}/www-new\" \"${deploy_root_dir}/www\""; echo "mv \"${deploy_root_dir}/www-new\" \"${deploy_root_dir}/www\"";
echo "rm -r \"${deploy_root_dir}/data/cache\""; echo "rm -r \"${deploy_root_dir}/data/cache\"";

View file

@ -54,7 +54,7 @@ class ListReadingTypes implements IAction {
if(!is_int($device_id)) if(!is_int($device_id))
$data = $this->types_repo->get_all_types(); $data = $this->types_repo->get_all_types();
else else
$data = $this->types_repo->get_types_by_device($device_id. $days_to_analyse); $data = $this->types_repo->get_types_by_device($device_id, $days_to_analyse);
$this->perfcounter->end("sql"); $this->perfcounter->end("sql");
// 1.5: Validate data from database // 1.5: Validate data from database
@ -86,7 +86,7 @@ class ListReadingTypes implements IAction {
// Don't a cache control header, because new types might get added at any time // Don't a cache control header, because new types might get added at any time
// TODO: Investigate adding a short-term (~10mins?) cache-control header here // TODO: Investigate adding a short-term (~10mins?) cache-control header here
header("content-length: " . strlen($response)); // header("content-length: " . strlen($response));
header("content-type: $response_type"); header("content-type: $response_type");
header("content-disposition: inline; filename=$response_suggested_filename"); header("content-disposition: inline; filename=$response_suggested_filename");
header("x-time-taken: " . $this->perfcounter->render()); header("x-time-taken: " . $this->perfcounter->render());

View file

@ -36,5 +36,5 @@ interface IMeasurementTypeRepository {
* @param int $day_to_analyse The number of days worth fo data to analyse. Defaults to -1, which is everything. Set to 0 for readings recorded in the last 24 hours, which is much faster. * @param int $day_to_analyse The number of days worth fo data to analyse. Defaults to -1, which is everything. Set to 0 for readings recorded in the last 24 hours, which is much faster.
* @return string[] A list of device ids. * @return string[] A list of device ids.
*/ */
public function get_types_by_device(int $device_id, int $days_to_analyse); public function get_types_by_device(int $device_id, int $days_to_analyse = -1);
} }

View file

@ -82,6 +82,12 @@ class MariaDBMeasurementTypeRepository implements IMeasurementTypeRepository {
} }
public function get_types_by_device($device_id, $days_to_analyse = -1) { public function get_types_by_device($device_id, $days_to_analyse = -1) {
$data = [
"device_id" => $device_id
];
if($days_to_analyse >= 0)
$data["days"] = $days_to_analyse;
$s = $this->get_static; $s = $this->get_static;
$o = $this->get_static_extra; $o = $this->get_static_extra;
return $this->database->query( return $this->database->query(
@ -95,10 +101,9 @@ class MariaDBMeasurementTypeRepository implements IMeasurementTypeRepository {
{$s("table_name")}.{$s("column_id")} = {$o(MariaDBMeasurementDataRepository::class, "table_name_values")}.{$o(MariaDBMeasurementDataRepository::class, "column_values_reading_type")} {$s("table_name")}.{$s("column_id")} = {$o(MariaDBMeasurementDataRepository::class, "table_name_values")}.{$o(MariaDBMeasurementDataRepository::class, "column_values_reading_type")}
WHERE WHERE
{$o(MariaDBMeasurementDataRepository::class, "table_name_metadata")}.{$o(MariaDBMeasurementDataRepository::class, "column_metadata_device_id")} = :device_id {$o(MariaDBMeasurementDataRepository::class, "table_name_metadata")}.{$o(MariaDBMeasurementDataRepository::class, "column_metadata_device_id")} = :device_id
" . ($days_to_analyse >= 0 ? "AND and DATEDIFF(NOW(),s_or_r) = 0" : "") . " " . ($days_to_analyse >= 0 ? "AND DATEDIFF(NOW(),s_or_r) = :days" : "") . "
GROUP BY {$s("table_name")}.{$s("column_id")};", [ GROUP BY {$s("table_name")}.{$s("column_id")};",
"device_id" => $device_id $data
]
)->fetchAll(); )->fetchAll();
} }
} }