fix(sns): fallback to userName when user_name count is zero

This commit is contained in:
aits2026
2026-03-05 17:33:41 +08:00
parent db0ebc6c33
commit 38af8de469

View File

@@ -881,15 +881,15 @@ class SnsService {
`SELECT COUNT(1) AS total FROM SnsTimeLine WHERE user_name = '${escapedUsername}'`
)
if (primaryResult.success) {
const totalPosts = primaryResult.rows && primaryResult.rows.length > 0
? this.parseCountValue(primaryResult.rows[0])
: 0
const primaryTotal = (primaryResult.success && primaryResult.rows && primaryResult.rows.length > 0)
? this.parseCountValue(primaryResult.rows[0])
: 0
if (primaryResult.success && primaryTotal > 0) {
return {
success: true,
data: {
username: normalizedUsername,
totalPosts
totalPosts: primaryTotal
}
}
}
@@ -901,14 +901,24 @@ class SnsService {
)
if (fallbackResult.success) {
const totalPosts = fallbackResult.rows && fallbackResult.rows.length > 0
const fallbackTotal = fallbackResult.rows && fallbackResult.rows.length > 0
? this.parseCountValue(fallbackResult.rows[0])
: 0
return {
success: true,
data: {
username: normalizedUsername,
totalPosts
totalPosts: Math.max(primaryTotal, fallbackTotal)
}
}
}
if (primaryResult.success) {
return {
success: true,
data: {
username: normalizedUsername,
totalPosts: primaryTotal
}
}
}