mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
* feat(quota): add database-backed resource quota system * feat(webui): add resource quota management in team settings (#319) * feat(webui): add resource quota settings in team management * refactor(webui): update quotas list to full row layout and restrict skill/mcp to select list * feat(quota): refactor quota system to 2-level rules and records * fix(webui): fix overflow and scroll area in quota usage records dialog * fix(webui): ensure quota records scroll area has explicit max height * feat(webui): improve quota cards interaction and restrict editable fields in edit mode * fix(quota): serialize initial records, validate merged updates, and reset on dimension changes (#320) * feat(quota): replace network quota with agent tools quota (#321) * feat(webui): show remaining time until next refresh in quota usage records * fix(webui): rename bash quota resource to Agent Bash Calls * refactor(quota): remove unused reserved field from quota records * refactor(quota): remove quota rule cache (#322)
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { Prisma } from '@shumai/db'
|
|
import { AssetType } from '@shumai/db'
|
|
|
|
interface DedupeSymlinksParams {
|
|
/** Files being merged into a version stack — symlinks pointing at them are the candidates. */
|
|
targetIds: string[]
|
|
/** The version stack the files are moving into. */
|
|
newTargetId: string
|
|
/** Optional name to set on repointed symlinks ('' for stacks — display name comes from the latest version). */
|
|
name?: string
|
|
}
|
|
|
|
/**
|
|
* When files are merged into a version stack, symlinks in share folders that
|
|
* pointed at those files must either be repointed to the stack (one per parent)
|
|
* or deleted as duplicates. Per parent folder: if the parent already shows the
|
|
* stack (either before this call or after the first repoint), delete the
|
|
* incoming symlink and decrement the parent's fileCount; otherwise repoint the
|
|
* first symlink to the stack.
|
|
*/
|
|
export async function dedupeSymlinksToTarget(
|
|
tx: Prisma.TransactionClient,
|
|
{ targetIds, newTargetId, name }: DedupeSymlinksParams,
|
|
): Promise<void> {
|
|
const existingSymlinks = await tx.asset.findMany({
|
|
where: { targetId: { in: targetIds }, type: AssetType.symlink },
|
|
orderBy: { id: 'asc' },
|
|
})
|
|
if (existingSymlinks.length === 0) return
|
|
|
|
// Parents that already display the stack (or will after the first repoint).
|
|
const stackSymlinkParents = new Set(
|
|
(
|
|
await tx.asset.findMany({
|
|
where: { targetId: newTargetId, type: AssetType.symlink },
|
|
select: { parentId: true },
|
|
})
|
|
)
|
|
.map((s) => s.parentId)
|
|
.filter((id): id is string => !!id),
|
|
)
|
|
|
|
for (const symlink of existingSymlinks) {
|
|
if (!symlink.parentId) continue
|
|
if (stackSymlinkParents.has(symlink.parentId)) {
|
|
await tx.asset.delete({ where: { id: symlink.id } })
|
|
await tx.asset.update({
|
|
where: { id: symlink.parentId },
|
|
data: { fileCount: { decrement: 1 } },
|
|
})
|
|
} else {
|
|
stackSymlinkParents.add(symlink.parentId)
|
|
await tx.asset.update({
|
|
where: { id: symlink.id },
|
|
data: { targetId: newTargetId, ...(name !== undefined ? { name } : {}) },
|
|
})
|
|
}
|
|
}
|
|
}
|