public function updatePeerRemoteTimeOnline(int $peerRemoteId, $time) {
$this->_debug->query->update->total++;
$query = $this->_db->prepare('UPDATE `peerRemote` SET `timeOnline` = ?, `timeUpdated` = ? WHERE `peerRemoteId` = ? LIMIT 1');
$query->execute([$time, $time, $peerRemoteId]);
return $query->rowCount();
}
public function findPeerRemote(int $peerId, string $scheme, string $host, int $port) {
public function findPeerRemote(int $peerId, string $scheme, string $host, int $port) {
$this->_debug->query->select->total++;
$this->_debug->query->select->total++;
@ -162,9 +174,9 @@ class MySQL {
$this->_debug->query->insert->total++;
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `peerCoordinate` SET `peerId` = ?,
$query = $this->_db->prepare('INSERT INTO `peerCoordinate` SET `peerId` = ?,
`port` = ?,
`port` = ?,
`timeAdded` = ?');
`timeAdded` = ?');
$query->execute([$peerId, $port, $timeAdded]);
$query->execute([$peerId, $port, $timeAdded]);
@ -217,6 +229,62 @@ class MySQL {
return $query->fetchAll();
return $query->fetchAll();
}
}
// Analytics
public function getPeerFirst() {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peer` ORDER BY `peerId` ASC LIMIT 1');
$query->execute();
return $query->fetch();
}
public function getPeerTotal() {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `peer`');
$query->execute();
return $query->fetch()->total;
}
public function findPeerTotalByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : 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` < ?)');
public function findPeerRemoteReceivedSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : 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` < ?)');
public function findPeerRemoteSentSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : 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` < ?)');