кэшируемый топ запрос
This commit is contained in:
parent
8b9c1e3da4
commit
0f387df75a
24
index.js
24
index.js
@ -212,6 +212,11 @@ function baseRowData(row)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let topCache = {};
|
||||||
|
setInterval(() => {
|
||||||
|
topCache = {};
|
||||||
|
}, 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
io.on('connection', function(socket)
|
io.on('connection', function(socket)
|
||||||
{
|
{
|
||||||
socket.on('recentTorrents', function(callback)
|
socket.on('recentTorrents', function(callback)
|
||||||
@ -445,17 +450,24 @@ io.on('connection', function(socket)
|
|||||||
where = ' and `added` > DATE_SUB(NOW(), INTERVAL 30 DAY) '
|
where = ' and `added` > DATE_SUB(NOW(), INTERVAL 30 DAY) '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mysqlPool.query(`SELECT * FROM torrents WHERE seeders > 0 and (contentCategory is null or contentCategory != 'xxx') ${where} ORDER BY seeders + leechers DESC LIMIT ${max}`, function (error, rows) {
|
|
||||||
|
const query = `SELECT * FROM torrents WHERE seeders > 0 and (contentCategory is null or contentCategory != 'xxx') ${where} ORDER BY seeders + leechers DESC LIMIT ${max}`;
|
||||||
|
if(topCache[query])
|
||||||
|
{
|
||||||
|
callback(topCache[query]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mysqlPool.query(query, function (error, rows) {
|
||||||
if(!rows || rows.length == 0) {
|
if(!rows || rows.length == 0) {
|
||||||
callback(undefined)
|
callback(undefined)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let searchList = [];
|
rows = rows.map((row) => {
|
||||||
rows.forEach((row) => {
|
return baseRowData(row);
|
||||||
searchList.push(baseRowData(row));
|
});
|
||||||
});
|
topCache[query] = rows;
|
||||||
callback(searchList);
|
callback(rows);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,14 +47,14 @@ export default class TopPage extends Page {
|
|||||||
window.router('/')
|
window.router('/')
|
||||||
}} />
|
}} />
|
||||||
{
|
{
|
||||||
this.types.map((type) => {
|
this.types.map((type, index) => {
|
||||||
const torrents = this.topTorrents[type];
|
const torrents = this.topTorrents[type];
|
||||||
|
|
||||||
if(!torrents)
|
if(!torrents)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List style={{paddingBottom: '70px'}} className='animated recent-torrents'>
|
<List key={index} style={{paddingBottom: '70px'}} className='animated recent-torrents'>
|
||||||
<Subheader inset={true}>
|
<Subheader inset={true}>
|
||||||
{
|
{
|
||||||
this.descriptions[type]
|
this.descriptions[type]
|
||||||
|
Loading…
Reference in New Issue
Block a user