admin: count actual item placements
This commit is contained in:
@@ -1725,7 +1725,7 @@ async function countTierListsUsingTopicItem(itemId) {
|
||||
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT id, is_public, groups_json, pool_json
|
||||
SELECT id, is_public, groups_json
|
||||
FROM tierlists
|
||||
`
|
||||
)
|
||||
@@ -1736,10 +1736,8 @@ async function countTierListsUsingTopicItem(itemId) {
|
||||
|
||||
rows.forEach((row) => {
|
||||
const groups = parseJson(row.groups_json, [])
|
||||
const pool = parseJson(row.pool_json, [])
|
||||
const inGroups = groups.some((group) => (group?.itemIds || []).includes(itemId))
|
||||
const inPool = pool.some((item) => item?.id === itemId)
|
||||
if (!inGroups && !inPool) return
|
||||
if (!inGroups) return
|
||||
totalCount += 1
|
||||
if (row.is_public) publicCount += 1
|
||||
else privateCount += 1
|
||||
@@ -1819,7 +1817,7 @@ async function findCustomItemById(id) {
|
||||
async function getCustomItemUsageMeta() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT t.topic_id, tp.name AS topic_name, t.groups_json, t.pool_json
|
||||
SELECT t.topic_id, tp.name AS topic_name, t.groups_json
|
||||
FROM tierlists t
|
||||
LEFT JOIN topics tp ON tp.id = t.topic_id
|
||||
`
|
||||
@@ -1829,7 +1827,6 @@ async function getCustomItemUsageMeta() {
|
||||
|
||||
rows.forEach((row) => {
|
||||
const groups = parseJson(row.groups_json, [])
|
||||
const pool = parseJson(row.pool_json, [])
|
||||
const seenItemIds = new Set()
|
||||
|
||||
groups.forEach((group) => {
|
||||
@@ -1839,13 +1836,6 @@ async function getCustomItemUsageMeta() {
|
||||
})
|
||||
})
|
||||
|
||||
pool.forEach((item) => {
|
||||
if (item?.id) {
|
||||
usageMap.set(item.id, (usageMap.get(item.id) || 0) + 1)
|
||||
seenItemIds.add(item.id)
|
||||
}
|
||||
})
|
||||
|
||||
if (!row.topic_id) return
|
||||
|
||||
seenItemIds.forEach((itemId) => {
|
||||
@@ -2013,7 +2003,7 @@ async function listCustomItems({ queryText = '', page = 1, limit = 50, filterMod
|
||||
createdAt: Number(row.created_at),
|
||||
ownerName: row.topic_name || row.topic_id,
|
||||
ownerEmail: '',
|
||||
usageCount: (templateLinkedBySrc.get(row.src) || new Map()).size,
|
||||
usageCount: usageMeta.usageMap.get(row.id) || 0,
|
||||
linkedTemplates: Array.from((templateLinkedBySrc.get(row.src) || new Map()).values()),
|
||||
assetKind: resolveLibraryAssetKind(row.src),
|
||||
sourceType: 'template',
|
||||
|
||||
Reference in New Issue
Block a user