diff --git a/miniapp/config/index.js b/miniapp/config/index.js index 6bdbd8d..7794e45 100644 --- a/miniapp/config/index.js +++ b/miniapp/config/index.js @@ -23,7 +23,7 @@ const ENV = { } // 当前环境 - 开发时使用 development,打包时改为 production -const CURRENT_ENV = 'production' +const CURRENT_ENV = 'development' // 导出配置 export const config = { diff --git a/server/cleanup_duplicate_views.sql b/server/cleanup_duplicate_views.sql deleted file mode 100644 index 493a54c..0000000 --- a/server/cleanup_duplicate_views.sql +++ /dev/null @@ -1,24 +0,0 @@ --- 清理 UserView 表中的重复记录 --- 保留每对用户(UserId + TargetUserId)的最新一条记录 - --- 首先查看有多少重复记录 -SELECT UserId, TargetUserId, COUNT(*) as cnt -FROM UserView -GROUP BY UserId, TargetUserId -HAVING COUNT(*) > 1; - --- 删除重复记录,保留 Id 最大的那条(即最新的) -DELETE FROM UserView -WHERE Id NOT IN ( - SELECT MaxId FROM ( - SELECT MAX(Id) as MaxId - FROM UserView - GROUP BY UserId, TargetUserId - ) AS KeepRecords -); - --- 验证清理结果 -SELECT UserId, TargetUserId, COUNT(*) as cnt -FROM UserView -GROUP BY UserId, TargetUserId -HAVING COUNT(*) > 1; diff --git a/server/src/XiangYi.Application/Services/InteractService.cs b/server/src/XiangYi.Application/Services/InteractService.cs index b3560b4..8217373 100644 --- a/server/src/XiangYi.Application/Services/InteractService.cs +++ b/server/src/XiangYi.Application/Services/InteractService.cs @@ -789,22 +789,45 @@ public class InteractService : IInteractService return new InteractCountsResponse(); } - // 获取用户最后查看各类互动的时间,如果为空则使用用户创建时间 - var lastViewedMeTime = user.LastViewedMeReadTime ?? user.CreateTime; - var lastFavoritedMeTime = user.LastFavoritedMeReadTime ?? user.CreateTime; - var lastUnlockedMeTime = user.LastUnlockedMeReadTime ?? user.CreateTime; + // 如果用户从未查看过互动列表,初始化已读时间为当前时间 + // 这样只统计从现在开始的新互动,避免历史数据一直显示未读 + var needUpdate = false; + var now = DateTime.Now; + + if (user.LastViewedMeReadTime == null) + { + user.LastViewedMeReadTime = now; + needUpdate = true; + } + if (user.LastFavoritedMeReadTime == null) + { + user.LastFavoritedMeReadTime = now; + needUpdate = true; + } + if (user.LastUnlockedMeReadTime == null) + { + user.LastUnlockedMeReadTime = now; + needUpdate = true; + } + + if (needUpdate) + { + user.UpdateTime = now; + await _userRepository.UpdateAsync(user); + _logger.LogInformation("初始化用户互动已读时间: UserId={UserId}", userId); + } // 统计各类互动的新增数量 // 看过我:统计首次查看时间(CreateTime)在上次已读之后的新用户数量 // 这样同一用户多次查看只计算一次(首次查看时) var viewedMeCount = await _viewRepository.CountAsync(v => - v.TargetUserId == userId && v.CreateTime > lastViewedMeTime); + v.TargetUserId == userId && v.CreateTime > user.LastViewedMeReadTime); var favoritedMeCount = await _favoriteRepository.CountAsync(f => - f.TargetUserId == userId && f.CreateTime > lastFavoritedMeTime); + f.TargetUserId == userId && f.CreateTime > user.LastFavoritedMeReadTime); var unlockedMeCount = await _unlockRepository.CountAsync(u => - u.TargetUserId == userId && u.CreateTime > lastUnlockedMeTime); + u.TargetUserId == userId && u.CreateTime > user.LastUnlockedMeReadTime); return new InteractCountsResponse {