public function findPeerRemote(int $peerId, int $peerRemoteSchemeId, int $peerRemoteHostId, int $peerRemotePortId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peerRemote` WHERE `peerId` = ? AND `peerRemoteSchemeId` = ? AND `peerRemoteHostId` = ? AND `peerRemotePortId` = ? LIMIT 1');
@ -196,29 +325,18 @@ class MySQL {
@@ -196,29 +325,18 @@ class MySQL {
return $this->_db->lastInsertId();
}
public function flushPeerCoordinateRoute(int $peerCoordinateId) {
$this->_debug->query->delete->total++;
$query = $this->_db->prepare('DELETE FROM `peerCoordinateRoute` WHERE `peerCoordinateId` = ?');
$query->execute([$peerCoordinateId]);
return $query->rowCount();
}
public function getLastCoordinate(int $peerId) {
public function findLastPeerCoordinateByPeerId(int $peerId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peerCoordinate` WHERE `peerId` = ? ORDER BY `timeAdded` DESC LIMIT 1');
$query = $this->_db->prepare('SELECT * FROM `peerCoordinate` WHERE `peerId` = ? ORDER BY `peerCoordinateId` DESC LIMIT 1');
$query->execute([$peerId]);
return $query->fetch();
}
public function getPeerCoordinateRoute(int $peerCoordinateId) {
public function findPeerCoordinateRouteByCoordinateId(int $peerCoordinateId) {
$this->_debug->query->select->total++;
@ -230,65 +348,259 @@ class MySQL {
@@ -230,65 +348,259 @@ class MySQL {
}
// Analytics
public function getPeerFirst() {
public function getPeerFirstByTimeAdded() {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peer` ORDER BY `peerId` ASC LIMIT 1');
$query = $this->_db->prepare('SELECT * FROM `peer` ORDER BY `timeAdded` ASC LIMIT 1');
$query->execute();
return $query->fetch();
}
public function getPeerTotal() {
public function findPeerSessionReceivedSumByTimeUpdated(int $timeFrom, int $timeTo, int $requestPeerId = 0) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `peer`');
$query = $this->_db->prepare('SELECT SUM(`received`) AS `result`
$query->execute();
FROM `peerSession`
WHERE `timeUpdated` >= :timeFrom AND `timeUpdated` <= :timeTo' . ($requestPeerId > 0 ? ' AND `peerId` = ' . (int) $requestPeerId : false));
return $query->fetch()->total;
$query->execute(
[
':timeFrom' => $timeFrom,
':timeTo' => $timeTo
]
);
return (int) $query->fetch()->result;
}
public function findPeerTotalByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
public function findPeerSessionSentSumByTimeUpdated(int $timeFrom, int $timeTo, int $requestPeerId = 0) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `peerId`) AS `total` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query = $this->_db->prepare('SELECT SUM(`sent`) AS `result`
FROM `peerSession`
WHERE `timeUpdated` >= :timeFrom AND `timeUpdated` <= :timeTo' . ($requestPeerId > 0 ? ' AND `peerId` = ' . (int) $requestPeerId : false));
public function findPeerRemoteReceivedSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
public function findPeerTotalByTimeAdded(int $timeFrom, int $timeTo, int $requestPeerId = 0) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT SUM(`received`) AS `result` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `peerId`) AS `result`
FROM `peerSession` WHERE `timeAdded` >= :timeFrom AND `timeAdded` <= :timeTo' .
public function findPeerRemoteSentSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
public function findPeerTotalByTimeUpdated(int $timeFrom, int $timeTo, int $requestPeerId = 0) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT SUM(`sent`) AS `result` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `peerId`) AS `result`