perf(feedback): дедуп и лимит 15 версий истории, единый хелпер в lib/feedback-versions
This commit is contained in:
@@ -4600,7 +4600,7 @@ app.post('/api/feedbacks', requireAuth, asyncRoute(async (req, res) => {
|
||||
);
|
||||
const fb = insert.rows[0];
|
||||
await client.query('COMMIT');
|
||||
await saveFeedbackVersion(fb.id, text || '', 'manual', req.user.id);
|
||||
await saveFeedbackVersion(pool, fb.id, text || '', 'manual', req.user.id);
|
||||
await logAudit(req, 'feedback.create', { id: fb.id, group_id: groupId, resident, ai_check: aiCheck, ai_profile: aiProfile || null, ai_status: fb.ai_status, short_count: shortIds.length });
|
||||
invalidateFeedbacks();
|
||||
invalidateStats();
|
||||
@@ -6016,7 +6016,7 @@ app.put('/api/feedbacks/:id', requireAuth, asyncRoute(async (req, res) => {
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
await saveFeedbackVersion(id, text || '', 'manual', req.user.id);
|
||||
await saveFeedbackVersion(pool, id, text || '', 'manual', req.user.id);
|
||||
invalidateFeedbacks();
|
||||
invalidateStats();
|
||||
if (shortsTouched) invalidateShorts();
|
||||
@@ -9244,7 +9244,8 @@ const LESSON_REPORT_LIST_TTL_MS = 30 * 1000;
|
||||
const LESSON_AI_VERSION_LIMIT = 50;
|
||||
const LESSON_AI_TIMEOUT_MS = 120000;
|
||||
|
||||
const FEEDBACK_AI_VERSION_LIMIT = 50;
|
||||
const { saveFeedbackVersion, FEEDBACK_VERSIONS_LIMIT } = require('./lib/feedback-versions');
|
||||
const FEEDBACK_AI_VERSION_LIMIT = FEEDBACK_VERSIONS_LIMIT;
|
||||
const FEEDBACK_AI_TIMEOUT_MS = 120000;
|
||||
const FEEDBACK_LIST_TTL_MS = 30 * 1000;
|
||||
const FEEDBACK_TEXT_MAX = 5000;
|
||||
@@ -9374,22 +9375,6 @@ function parseLessonReportTime(v) {
|
||||
return s.length === 5 ? s + ':00' : s;
|
||||
}
|
||||
|
||||
async function saveFeedbackVersion(feedbackId, text, source, userId) {
|
||||
if (!text || !text.trim()) return null;
|
||||
const { rows } = await pool.query(
|
||||
`INSERT INTO feedback_versions (feedback_id, text, source, author_id)
|
||||
VALUES ($1, $2, $3, $4) RETURNING *`,
|
||||
[feedbackId, text, source, userId || null]
|
||||
);
|
||||
await pool.query(
|
||||
`DELETE FROM feedback_versions WHERE feedback_id = $1 AND id NOT IN (
|
||||
SELECT id FROM feedback_versions WHERE feedback_id = $1 ORDER BY id DESC LIMIT $2
|
||||
)`,
|
||||
[feedbackId, FEEDBACK_AI_VERSION_LIMIT]
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
async function saveLessonReportVersion(reportId, text, source, userId) {
|
||||
if (!text || !text.trim()) return null;
|
||||
const { rows } = await pool.query(
|
||||
@@ -9682,7 +9667,7 @@ app.post('/api/feedbacks/:id/versions/:versionId/restore', requireAuth, async (r
|
||||
[version.text, fb.id]
|
||||
);
|
||||
const d = textDiff(fb.text || '', version.text);
|
||||
await saveFeedbackVersion(fb.id, version.text, 'restore', req.user.id);
|
||||
await saveFeedbackVersion(pool, fb.id, version.text, 'restore', req.user.id);
|
||||
await logAudit(req, 'feedback.version.restore', {
|
||||
id: fb.id,
|
||||
changed: d.changed,
|
||||
|
||||
Reference in New Issue
Block a user