|
|
@@ -16,7 +16,6 @@ class MistakeBookService
|
|
|
protected int $timeout;
|
|
|
|
|
|
// 缓存时间(秒)
|
|
|
- const CACHE_TTL_LIST = 60; // 5分钟
|
|
|
const CACHE_TTL_SUMMARY = 600; // 10分钟
|
|
|
const CACHE_TTL_PATTERNS = 1800; // 30分钟
|
|
|
|
|
|
@@ -191,14 +190,6 @@ class MistakeBookService
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- // 构建缓存键
|
|
|
- $cacheKey = $this->buildCacheKey('list', $params);
|
|
|
-
|
|
|
- // 尝试从缓存获取
|
|
|
- if (Cache::has($cacheKey)) {
|
|
|
- return Cache::get($cacheKey);
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
$query = MistakeRecord::forStudent($studentId)
|
|
|
->with(['student']) // 预加载学生信息
|
|
|
@@ -223,7 +214,7 @@ class MistakeBookService
|
|
|
// 获取统计信息
|
|
|
$summary = $this->summarize($studentId);
|
|
|
|
|
|
- $result = [
|
|
|
+ return [
|
|
|
'data' => $data,
|
|
|
'meta' => [
|
|
|
'total' => $total,
|
|
|
@@ -231,14 +222,9 @@ class MistakeBookService
|
|
|
'per_page' => $perPage,
|
|
|
'last_page' => (int) ceil($total / $perPage),
|
|
|
],
|
|
|
- 'statistics' => $summary, // ✅ 添加统计信息
|
|
|
+ 'statistics' => $summary,
|
|
|
];
|
|
|
|
|
|
- // 缓存结果
|
|
|
- Cache::put($cacheKey, $result, self::CACHE_TTL_LIST);
|
|
|
-
|
|
|
- return $result;
|
|
|
-
|
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('获取错题列表失败', [
|
|
|
'student_id' => $studentId,
|
|
|
@@ -402,12 +388,9 @@ class MistakeBookService
|
|
|
default => throw new \InvalidArgumentException('无效的操作类型'),
|
|
|
};
|
|
|
|
|
|
- // ⚠️ 重要:重新加载模型数据以获取最新状态
|
|
|
+ // 重新加载模型数据以获取最新状态
|
|
|
$mistake->refresh();
|
|
|
|
|
|
- // 【修复】清除缓存,避免列表延迟显示更新
|
|
|
- $this->clearCache($mistake->student_id);
|
|
|
-
|
|
|
return [
|
|
|
'success' => true,
|
|
|
'mistake_id' => $mistakeId,
|
|
|
@@ -813,15 +796,6 @@ class MistakeBookService
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建缓存键
|
|
|
- */
|
|
|
- private function buildCacheKey(string $type, array $params): string
|
|
|
- {
|
|
|
- $key = "mistake_book:{$type}:" . md5(serialize($params));
|
|
|
- return $key;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 清除缓存
|
|
|
*/
|
|
|
@@ -829,7 +803,6 @@ class MistakeBookService
|
|
|
{
|
|
|
try {
|
|
|
$patterns = [
|
|
|
- "mistake_book:list:{$studentId}",
|
|
|
"mistake_book:summary:{$studentId}",
|
|
|
"mistake_book:patterns:{$studentId}",
|
|
|
];
|