Skip to content

Commit

Permalink
fix: /all data empty
Browse files Browse the repository at this point in the history
  • Loading branch information
BLxcwg666 committed Jul 26, 2024
1 parent 8a1b744 commit 4670371
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions routes/public/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const express = require('express');
const { Op } = require("sequelize");
const log = require('../../modules/logger');
const { rssModel } = require('../../modules/sqlModel');
const { webModel } = require('../../modules/sqlModel');
const redisClient = require('../../modules/redisClient');

const router = express.Router();
Expand All @@ -18,8 +18,8 @@ const router = express.Router();
redisClient.connect();

router.get('/', async (req, res) => {
const { tag } = req.query;
const cacheKey = `rss:${tag || 'all'}`;
const { status, tag } = req.query;
const cacheKey = `data:${status || 'all'}:${tag || 'all'}`;

try {
const cachedData = await redisClient.get(cacheKey);
Expand All @@ -31,16 +31,19 @@ router.get('/', async (req, res) => {
} else {
// 没有就返回数据库中的
// console.log('not found data from redis');
getDataFromDB(req, res, cacheKey, tag);
getDataFromDB(req, res, cacheKey, status, tag);
}
} catch (error) {
log.err(error, "RSS");
log.err(error, "ALL");
res.json({ success: false, msg: "出错了呜呜呜~ 请检查控制台输出喵~" });
}
});

async function getDataFromDB(req, res, cacheKey, tag) {
async function getDataFromDB(req, res, cacheKey, status, tag) {
let queryData = {};
if (status) {
queryData.status = status.toUpperCase();
}

if (tag) {
queryData.tag = {
Expand All @@ -50,16 +53,15 @@ async function getDataFromDB(req, res, cacheKey, tag) {

const queryOptions = { where: queryData };

const { rows } = await rssModel.findAndCountAll(queryOptions);
const { rows } = await webModel.findAndCountAll(queryOptions);

const data = rows.map(rss => ({
id: rss.id,
name: rss.name,
content: rss.status,
lastGot: rss.link,
originLink: rss.tag,
rssLink: rss.failedReason,
tag: rss.tag
const data = rows.map(web => ({
id: web.id,
name: web.name,
status: web.status,
url: web.link,
tag: web.tag,
failedReason: web.failedReason,
}));

// 写入 redis
Expand Down

0 comments on commit 4670371

Please sign in to comment.