消息接口优化

This commit is contained in:
2026-09-21 17:25:24 +08:00
parent 0620df79d3
commit 1f1164ab69
2 changed files with 63 additions and 5 deletions
+3 -3
View File
@@ -140,7 +140,7 @@ router.post(
authMiddleware,
(req, res) => {
const currentUserName = req.user.username;
const { contactName, limit } = req.body;
const { contactName, limit, offset } = req.body;
const sql = `
SELECT
id,
@@ -150,9 +150,9 @@ router.post(
created_at
FROM chat_mysql.messages
WHERE (sender_name = ? OR receiver_name = ?) AND (sender_name = ? OR receiver_name = ?)
ORDER BY created_at ASC LIMIT ? ;
ORDER BY created_at DESC LIMIT ? OFFSET ?;
`;
db.query(sql, [currentUserName, currentUserName, contactName, contactName, limit], (error, results) => {
db.query(sql, [currentUserName, currentUserName, contactName, contactName, limit, offset], (error, results) => {
if (error) {
console.error("数据库查询失败:", error);