diff --git a/btsearch.sql b/btsearch.sql
index dbf435e..5dd9755 100644
--- a/btsearch.sql
+++ b/btsearch.sql
@@ -40,6 +40,29 @@ LOCK TABLES `files` WRITE;
/*!40000 ALTER TABLE `files` ENABLE KEYS */;
UNLOCK TABLES;
+--
+-- Table structure for table `statistic`
+--
+
+DROP TABLE IF EXISTS `statistic`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `statistic` (
+ `size` bigint(20) unsigned DEFAULT NULL,
+ `files` bigint(20) unsigned DEFAULT NULL,
+ `torrents` int(10) unsigned DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `statistic`
+--
+
+LOCK TABLES `statistic` WRITE;
+/*!40000 ALTER TABLE `statistic` DISABLE KEYS */;
+/*!40000 ALTER TABLE `statistic` ENABLE KEYS */;
+UNLOCK TABLES;
+
--
-- Table structure for table `torrents`
--
@@ -79,4 +102,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2017-01-02 11:33:56
+-- Dump completed on 2017-01-03 6:03:58
diff --git a/index.js b/index.js
index de4bb8c..6e1d2e9 100644
--- a/index.js
+++ b/index.js
@@ -74,6 +74,32 @@ app.get('*', function(req, res)
res.sendfile(__dirname + '/build/index.html');
});
+
+// start
+
+// обновление статистики
+setInterval(() => {
+ let stats = {};
+ socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
+ stats.torrents = rows[0].tornum;
+ socketMysql.query('SELECT COUNT(*) as filesnum, SUM(`size`) as filesizes FROM `files`', function (error, rows, fields) {
+ stats.files = rows[0].filesnum;
+ stats.size = rows[0].filesizes;
+ io.sockets.emit('newStatistic', stats);
+ socketMysql.query('DELETE FROM `statistic`', function (err, result) {
+ if(!result) {
+ console.error(err);
+ }
+ socketMysql.query('INSERT INTO `statistic` SET ?', stats, function(err, result) {
+ if(!result) {
+ console.error(err);
+ }
+ });
+ })
+ });
+ });
+}, 60 * 1000)
+
io.on('connection', function(socket)
{
function baseRowData(row)
@@ -109,13 +135,8 @@ io.on('connection', function(socket)
if(typeof callback != 'function')
return;
- let stats = {};
- socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
- stats.torrents = rows[0].tornum;
- socketMysql.query('SELECT COUNT(*) as filesnum FROM `files`', function (error, rows, fields) {
- stats.files = rows[0].filesnum;
- callback(stats)
- });
+ socketMysql.query('SELECT * FROM `statistic`', function (error, rows, fields) {
+ callback(rows[0])
});
});
diff --git a/src/recent-torrents.js b/src/recent-torrents.js
index 4560e1c..442a253 100644
--- a/src/recent-torrents.js
+++ b/src/recent-torrents.js
@@ -73,6 +73,9 @@ export default class RecentTorrents extends Component {
});
}
render() {
+ if(!this.torrents || this.torrents.length == 0)
+ return null;
+
return (
+
);
}
}
diff --git a/src/search.js b/src/search.js
index e88bfdf..bd9a773 100644
--- a/src/search.js
+++ b/src/search.js
@@ -5,6 +5,8 @@ import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';
import RefreshIndicator from 'material-ui/RefreshIndicator';
+import formatBytes from './format-bytes'
+
export default class Search extends Component {
constructor(props)
{
@@ -28,6 +30,10 @@ export default class Search extends Component {
this.stats = statistic;
this.forceUpdate();
});
+ window.torrentSocket.on('newStatistic', (statistic) => {
+ this.stats = statistic;
+ this.forceUpdate();
+ });
}
render() {
const style = {
@@ -59,7 +65,7 @@ export default class Search extends Component {
{
this.stats
?
-