~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/knotless

git that lives in your Atmosphere account

Forked from chadtmiller.com/knotless

0
0
55 lines · 2.0 KB Raw History
<script lang="ts">
	import type * as compactRepo from '#lib/lexicons/dev/knotless/compactRepo.ts';
	import type { StorageView } from '#lib/lexicons/dev/knotless/getRepoSettings.ts';
	import type { AtUriString } from '@atproto/lex';
	import { invalidateAll } from '$app/navigation';
	import { call } from '#lib/data.ts';
	import { number, plural, size } from '#lib/format.ts';
	/**
	 * What the repository `uri` names takes up on its owner's PDS,
	 * `storage`, as `knotless repo storage` counts it, once counted, and folding
	 * its packs into one, as `knotless repo compact` does.
	 */
	let { uri, storage }: { uri: AtUriString; storage: Promise<StorageView | null> } = $props();
	let done = $state('');
	let problem = $state('');
	let busy = $state(false);
	async function compact() {
		busy = true;
		problem = done = '';
		try {
			const c = await call<typeof compactRepo.main>('dev.knotless.compactRepo', { repo: uri });
			await invalidateAll();
			done = c.folded
				? `Folded ${plural(c.folded, 'pack', 'packs')} into one.`
				: 'Nothing to fold yet: packs younger than the grace period stay.';
		} catch (err) {
			problem = (err as Error).message;
		}
		busy = false;
	}
</script>

<section class="setting">
	<h2>Storage</h2>
	{#await storage}
		<p class="mute" data-loading>Counting its packs…</p>
	{:then counted}
		{#if counted}
			<p>
				{`${plural(counted.packs, 'pack', 'packs')}, ${number(counted.objects)} objects, ${size(counted.bytes)}, ${size(counted.blobBytes)} of it in blobs.`}
			</p>
		{:else}
			<p class="mute">What it takes up could not be read.</p>
		{/if}
	{/await}
	<p class="hint">
		Each push adds a pack. Compacting folds them into one, so clones read fewer records.
	</p>
	<div class="actions">
		<button class="btn" type="button" disabled={busy} aria-busy={busy} onclick={compact}
			>{busy ? 'Compacting…' : 'Compact'}</button
		>{#if done}<span class="mute" role="status">{done}</span>{/if}
	</div>
	{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
</section>