mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-02 17:59:53 +08:00
fix: 优化弹幕页面解析量速度
feat: 增加robots.txt文件 fix: 手动gc,尝试解决OOM问题
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node --max-old-space-size=200 ./bin/www",
|
||||
"dev": "nodemon --max-old-space-size=200 ./bin/www",
|
||||
"start": "node --expose-gc --max-old-space-size=200 ./bin/www",
|
||||
"dev": "nodemon --expose-gc --max-old-space-size=200 ./bin/www",
|
||||
"test": "nyc -a mocha --recursive",
|
||||
"deploy": "flyctl deploy"
|
||||
},
|
||||
|
||||
5
public/robots.txt
Normal file
5
public/robots.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# robots.txt generated at http://www.w3cschool.cn/
|
||||
User-agent: *
|
||||
Disallow:
|
||||
Crawl-delay: 120
|
||||
Disallow: /cgi-bin/
|
||||
@@ -61,6 +61,7 @@ function Iqiyi() {
|
||||
for (const xml of datas) {
|
||||
const json = await xml2js.parseStringPromise(xml)
|
||||
// console.log(json)
|
||||
global.gc()
|
||||
for (const entry of json.danmu.data[0].entry) {
|
||||
if (!entry.list[0].bulletInfo)
|
||||
continue
|
||||
@@ -74,6 +75,7 @@ function Iqiyi() {
|
||||
contents.push(content);
|
||||
}
|
||||
}
|
||||
memory()
|
||||
// $('bulletInfo').each(function () {
|
||||
// })
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ function getClientIp(req) {
|
||||
req.connection.socket.remoteAddress;
|
||||
}
|
||||
|
||||
async function build_response(url) {
|
||||
async function build_response(url,req) {
|
||||
try {
|
||||
await axios.get(url)
|
||||
} catch (e) {
|
||||
@@ -38,6 +38,7 @@ async function build_response(url) {
|
||||
ret = await fc.work(url)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
leancloud.danmakuErrorAdd({ip: getClientIp(req), url: url, error: e})
|
||||
return {msg: '弹幕解析过程中程序报错退出,请等待管理员修复!或者换条链接试试!'}
|
||||
}
|
||||
return ret
|
||||
@@ -54,7 +55,7 @@ router.get('/', async function (req, res, next) {
|
||||
} else {
|
||||
url = req.query.url;
|
||||
download = (req.query.download === 'on');
|
||||
ret = await build_response(url)
|
||||
ret = await build_response(url,req)
|
||||
memory() //显示内存使用量
|
||||
if (ret.msg !== 'ok') {
|
||||
res.status(403).send(ret.msg)
|
||||
@@ -69,9 +70,12 @@ router.get('/', async function (req, res, next) {
|
||||
});
|
||||
|
||||
router.get('/pageinfo', async function (req, res, next) {
|
||||
const today_visited = await leancloud.danmakuQuery(leancloud.currentDay());
|
||||
const lastday_visited = await leancloud.danmakuQuery(leancloud.lastDay());
|
||||
const month_visited = await leancloud.danmakuQuery(leancloud.currentMonth());
|
||||
const promises = [
|
||||
leancloud.danmakuQuery(leancloud.currentDay()),
|
||||
leancloud.danmakuQuery(leancloud.lastDay()),
|
||||
leancloud.danmakuQuery(leancloud.currentMonth())
|
||||
]
|
||||
const [today_visited, lastday_visited, month_visited] = await Promise.all(promises)
|
||||
res.json({today_visited, lastday_visited, month_visited})
|
||||
});
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ function currentDay() {
|
||||
const date = new Date();
|
||||
const start = new Date(date.setHours(0, 0, 0, 0))
|
||||
const end = new Date(date.setHours(23, 59, 59, 999))
|
||||
return [start,end]
|
||||
return [start, end]
|
||||
}
|
||||
|
||||
function lastDay() {
|
||||
@@ -55,11 +55,21 @@ async function danmakuQuery(date) {
|
||||
query.greaterThanOrEqualTo('createdAt', date[0]);
|
||||
query.lessThan('createdAt', date[1]);
|
||||
|
||||
// query.exists('url');
|
||||
query.exists('url');
|
||||
return await query.count()
|
||||
}
|
||||
|
||||
module.exports = {danmakuAccessAdd, danmakuQuery, currentDay, currentMonth, lastDay};
|
||||
function danmakuErrorAdd(obj) {
|
||||
const {ip, url, error} = obj;
|
||||
const DanmakuErrorObject = AV.Object.extend('DanmakuError');
|
||||
const record = new DanmakuErrorObject();
|
||||
record.set('remoteIP', ip);
|
||||
record.set('url', url);
|
||||
record.set('error', JSON.stringify(error));
|
||||
record.save().then()
|
||||
}
|
||||
|
||||
module.exports = {danmakuAccessAdd, danmakuQuery, currentDay, currentMonth, lastDay, danmakuErrorAdd};
|
||||
|
||||
if (!module.parent) {
|
||||
}
|
||||
|
||||
@@ -86,9 +86,9 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
今日访问量:<span id="today_visited"></span><span class="post-meta-divider"> | </span>
|
||||
昨日访问量:<span id="lastday_visited"></span><span class="post-meta-divider"> | </span>
|
||||
当月访问量:<span id="month_visited"></span>
|
||||
今日解析量:<span id="today_visited"></span><span class="post-meta-divider"> | </span>
|
||||
昨日解析量:<span id="lastday_visited"></span><span class="post-meta-divider"> | </span>
|
||||
当月解析量:<span id="month_visited"></span>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
|
||||
Reference in New Issue
Block a user