Skip to content
Snippets Groups Projects
Commit e59ced61 authored by Tibo's avatar Tibo
Browse files

Try to optimize mongo requests...

parent 0bcd1537
No related merge requests found
......@@ -26,10 +26,27 @@ abstract class AbstractSensor implements Sensor {
return $this->server->lastRecordContaining($field);
}
/**
* Get the last $count records containing $field.
* !! $count is the MAXIMUM number of returned records.
* To optimize mongo's usage of index, we get the last $count records
* then filter locally for records containing this record
* @param type $field
* @param type $count
* @return type
*/
function getLastRecords($field, $count) {
return \Mongo::get()->monitoring->records->find(
[ "server_id" => $this->server->id,
$field => ['$ne' => null]],
$records = \Mongo::get()->monitoring->records->find(
["server_id" => $this->server->id],
["limit" => $count, "sort" => ["_id" => -1]]);
$results = [];
foreach ($records as $record) {
if (isset($record->$field)) {
$results[] = $record;
}
}
return $results;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment