Add last_seen to list_devices_near

bugfix/performance
Starbeamrainbowlabs 4 years ago
parent 4e5a451cde
commit a678a89b95
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 1
      Changelog.md
  2. 10
      logic/Repositories/MariaDBDeviceRepository.php

@ -10,6 +10,7 @@ This is the changelog for the air quality web interface and its associated HTTP
## v0.13-dev
- Round dates before making API requests to improve caching potential
- [@Mr-Pepp](https://github.com/Mr-Pepp): Improve initial on-boarding tour
- Added `last_seen` to `list-devices-near` (#36)
## v0.12
- Added loading animation while the map is loading

@ -148,14 +148,22 @@ class MariaDBDeviceRepository implements IDeviceRepository {
public function get_near_location(float $lat, float $long, int $count) {
$s = $this->get_static;
$data_repo_class = MariaDBMeasurementDataRepository::class;
$data_repo_table_meta = $o($data_repo_class, "table_name_metadata");
$data_repo_col_datetime = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_datetime")}";
$data_repo_col_device_id = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_device_id")}";
$result = $this->database->query(
"SELECT
{$s("table_name")}.{$s("column_device_id")} AS id,
{$s("table_name")}.{$s("column_device_name")} AS name,
{$s("table_name")}.{$s("column_lat")} AS latitude,
{$s("table_name")}.{$s("column_long")} AS longitude,
ST_DISTANCE_SPHERE(POINT(:latitude, :longitude), {$s("table_name")}.{$s("column_point")}) AS distance_calc
ST_DISTANCE_SPHERE(POINT(:latitude, :longitude), {$s("table_name")}.{$s("column_point")}) AS distance_calc,
MAX($data_repo_col_datetime) AS last_seen
FROM {$s("table_name")}
JOIN $data_repo_table_meta ON
$data_repo_col_device_id = {$s("table_name")}.{$s("column_device_id")}
WHERE {$s("table_name")}.{$s("column_point")} IS NOT NULL
ORDER BY ST_DISTANCE_SPHERE(POINT(:latitude_again, :longitude_again), {$s("table_name")}.{$s("column_point")})
LIMIT :count;", [

Loading…
Cancel
Save