fix(admin): 修复 visitAnalytics 中 site_id 过滤不兼容旧数据的问题
- 查询条件改为匹配指定 siteId、空字符串或 NULL 值 - 确保统计和页面访问数据能正确包含旧数据
This commit is contained in:
@@ -35,8 +35,9 @@ export const getVisitOverview = async (
|
|||||||
const statsParams: any[] = [];
|
const statsParams: any[] = [];
|
||||||
|
|
||||||
if (siteId) {
|
if (siteId) {
|
||||||
statsSql += ' WHERE site_id = ?';
|
// 匹配指定 siteId 或空值(兼容旧数据)
|
||||||
statsParams.push(siteId);
|
statsSql += ' WHERE (site_id = ? OR site_id = ? OR site_id IS NULL)';
|
||||||
|
statsParams.push(siteId, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { results } = await c.env.CWD_DB.prepare(statsSql).bind(...statsParams).all<{
|
const { results } = await c.env.CWD_DB.prepare(statsSql).bind(...statsParams).all<{
|
||||||
@@ -98,11 +99,12 @@ export const getVisitOverview = async (
|
|||||||
|
|
||||||
let dailySql =
|
let dailySql =
|
||||||
'SELECT date, count FROM page_visit_daily WHERE date >= ?';
|
'SELECT date, count FROM page_visit_daily WHERE date >= ?';
|
||||||
const params: string[] = [earliestDate];
|
const params: any[] = [earliestDate];
|
||||||
|
|
||||||
if (siteId) {
|
if (siteId) {
|
||||||
dailySql += ' AND site_id = ?';
|
// 匹配指定 siteId 或空值(兼容旧数据)
|
||||||
params.push(siteId);
|
dailySql += ' AND (site_id = ? OR site_id = ? OR site_id IS NULL)';
|
||||||
|
params.push(siteId, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { results: dailyRows } = await c.env.CWD_DB.prepare(dailySql)
|
const { results: dailyRows } = await c.env.CWD_DB.prepare(dailySql)
|
||||||
@@ -232,8 +234,9 @@ export const getVisitPages = async (c: Context<{ Bindings: Bindings }>) => {
|
|||||||
const params: any[] = [];
|
const params: any[] = [];
|
||||||
|
|
||||||
if (siteId) {
|
if (siteId) {
|
||||||
sql += ' WHERE site_id = ?';
|
// 匹配指定 siteId 或空值(兼容旧数据)
|
||||||
params.push(siteId);
|
sql += ' WHERE (site_id = ? OR site_id = ? OR site_id IS NULL)';
|
||||||
|
params.push(siteId, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { results } = await c.env.CWD_DB.prepare(sql).bind(...params).all<{
|
const { results } = await c.env.CWD_DB.prepare(sql).bind(...params).all<{
|
||||||
|
|||||||
Reference in New Issue
Block a user