watch update
This commit is contained in:
parent
326201fb2f
commit
dfab62b437
@ -75,6 +75,14 @@ async function update() {
|
||||
/**
|
||||
* 统计数据库中数据
|
||||
*/
|
||||
let watchParam = {
|
||||
songCount: 0,
|
||||
albumCount: 0,
|
||||
artistCount: 0,
|
||||
lyricCount: 0,
|
||||
commentCount: 0,
|
||||
commentTotalCount: 0,
|
||||
};
|
||||
async function watch() {
|
||||
let sql = `
|
||||
SELECT
|
||||
@ -88,7 +96,9 @@ async function watch() {
|
||||
artist_waiting,
|
||||
|
||||
lyric_count,
|
||||
lyric_waiting,
|
||||
|
||||
comment_count,
|
||||
comment_total_count,
|
||||
|
||||
song_album_count,
|
||||
song_artist_count
|
||||
@ -104,12 +114,16 @@ async function watch() {
|
||||
( SELECT count( DISTINCT artist_id ) as artist_waiting FROM song_artist_relation WHERE artist_id NOT IN ( SELECT DISTINCT artist_id FROM artist ) ) as t_album_waiting_song_artist,
|
||||
|
||||
( SELECT count(*) AS lyric_count FROM lyric ) t_lyric,
|
||||
( SELECT count( DISTINCT song_id ) as lyric_waiting FROM song WHERE song_id NOT IN ( SELECT DISTINCT song_id FROM lyric ) ) as t_lyric_waiting_song,
|
||||
|
||||
( SELECT count( DISTINCT song_id ) AS comment_count, count( comment_id ) AS comment_total_count FROM comment ) t_comment,
|
||||
|
||||
( SELECT count(*) AS song_album_count FROM song_album_relation ) t_song_album,
|
||||
( SELECT count(*) AS song_artist_count FROM song_artist_relation ) t_song_artist
|
||||
`;
|
||||
console.log("开始统计 ...");
|
||||
let startTime = Date.now();
|
||||
let result = await dbUtils.query(sql, []);
|
||||
let timeSpent = Date.now() - startTime;
|
||||
|
||||
let songCount = result[0].song_count;
|
||||
let songWaiting = result[0].song_waiting;
|
||||
@ -121,19 +135,35 @@ async function watch() {
|
||||
let artistWaiting = result[0].artist_waiting;
|
||||
|
||||
let lyricCount = result[0].lyric_count;
|
||||
let lyricWaiting = result[0].lyric_waiting;
|
||||
|
||||
let commentCount = result[0].comment_count;
|
||||
let commentTotalCount = result[0].comment_total_count;
|
||||
|
||||
let songAlbumCount = result[0].song_album_count;
|
||||
let songArtistCount = result[0].song_artist_count;
|
||||
let statisticsString = [
|
||||
`song: ${songCount}/${songCount + songWaiting}`,
|
||||
`album: ${albumCount}/${albumCount + albumWaiting}`,
|
||||
`artist: ${artistCount}/${artistCount + artistWaiting}`,
|
||||
`lyric: ${lyricCount}/${lyricCount + lyricWaiting}`,
|
||||
`songAlbum: ${songAlbumCount}`,
|
||||
`songArtist: ${songArtistCount}`
|
||||
].join(', ');
|
||||
`[与上次运行统计时相比]`,
|
||||
`song: ${songCount - watchParam.songCount}, album: ${albumCount - watchParam.albumCount}, artist: ${artistCount - watchParam.artistCount}, lyric: ${lyricCount - watchParam.lyricCount}, comment: ${commentCount - watchParam.commentCount}(song)/${commentTotalCount - watchParam.commentTotalCount}(comment)`,
|
||||
`[已爬取]`,
|
||||
`song: ${songCount}, album: ${albumCount}, artist: ${artistCount}, lyric: ${lyricCount}, comment: ${commentCount}(song)/${commentTotalCount}(comment)`,
|
||||
`[待爬取]`,
|
||||
`song: ${songWaiting}, album: ${albumWaiting}, artist: ${artistWaiting}, lyric: ${songCount - lyricCount}, comment: ${songCount - commentCount}`,
|
||||
`[总计] (已爬取 + 待爬取)`,
|
||||
`song: ${songCount + songWaiting}, album: ${albumCount + albumWaiting}, artist: ${artistCount + artistWaiting}, lyric: ${songCount}, comment: ${songCount}`,
|
||||
`[关联关系统计]`,
|
||||
`song-album: ${songAlbumCount}, song-artist: ${songArtistCount}`,
|
||||
`time spent: ${timeSpent}ms(${(timeSpent / 1000).toFixed(2)}s)`,
|
||||
``
|
||||
].join('\n');
|
||||
console.log(statisticsString);
|
||||
watchParam = {
|
||||
songCount: songCount,
|
||||
albumCount: albumCount,
|
||||
artistCount: artistCount,
|
||||
lyricCount: lyricCount,
|
||||
commentCount: commentCount,
|
||||
commentTotalCount: commentTotalCount,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,9 @@ const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
// refer:
|
||||
// https://neteasecloudmusicapi-docs.4everland.app/
|
||||
// https://github.com/Binaryify/NeteaseCloudMusicApi
|
||||
const { comment_music } = require('NeteaseCloudMusicApi');
|
||||
|
||||
async function fetchAll() {
|
||||
|
9
watch.js
9
watch.js
@ -1,11 +1,12 @@
|
||||
const neteaseMusic = require('./netease_music/index');
|
||||
|
||||
let keepWatching = false;
|
||||
let keepWatching = true;
|
||||
if (keepWatching) {
|
||||
global.useMysqlPool = true;
|
||||
global.connectionLimit = 1;
|
||||
setInterval(neteaseMusic.watch, 10 * 1000);
|
||||
} else {
|
||||
global.useMysqlPool = false;
|
||||
}
|
||||
|
||||
const neteaseMusic = require('./netease_music/index');
|
||||
neteaseMusic.watch();
|
||||
if (keepWatching)
|
||||
setInterval(neteaseMusic.watch, 15 * 1000);
|
Loading…
Reference in New Issue
Block a user