mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
b7e45f0768
commit
ae02ff020a
5 changed files with 0 additions and 105 deletions
|
@ -3,16 +3,11 @@
|
|||
|
||||
import { PackageStates, type GUIPackage } from "$libs/types";
|
||||
import { packagesStore } from "$libs/stores";
|
||||
import { onMount } from "svelte";
|
||||
import PackageCard from "$components/package-card/package-card.svelte";
|
||||
|
||||
export let tab = "all";
|
||||
export let pkg: GUIPackage;
|
||||
export let layout: "bottom" | "left" | "right" = "bottom";
|
||||
|
||||
onMount(() => {
|
||||
packagesStore.fetchPackageBottles(pkg.full_name);
|
||||
});
|
||||
</script>
|
||||
|
||||
<PackageCard
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<script lang="ts">
|
||||
import type { GUIPackage } from "$libs/types";
|
||||
import { packagesStore } from "$libs/stores";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
import ImgLoader from "@tea/ui/img-loader/img-loader.svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
|
@ -14,10 +13,6 @@
|
|||
|
||||
$: updatedPkg = $packageList.find((p) => p.full_name === pkg.full_name);
|
||||
|
||||
onMount(() => {
|
||||
packagesStore.fetchPackageBottles(pkg.full_name);
|
||||
});
|
||||
|
||||
const gotoPackagePage = () => {
|
||||
goto(`/packages/${pkg.slug}?tab=all`);
|
||||
onClose();
|
||||
|
|
|
@ -123,19 +123,6 @@ export async function getAllPosts(tag?: string): Promise<AirtablePost[]> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getPackageBottles(packageName: string): Promise<Bottle[]> {
|
||||
try {
|
||||
return withRetry(async () => {
|
||||
const pkg = await apiGet<Package>(`packages/${packageName.replaceAll("/", ":")}`);
|
||||
log.info(`got ${pkg?.bottles?.length || 0} bottles for ${packageName}`);
|
||||
return (pkg && pkg.bottles) || [];
|
||||
});
|
||||
} catch (error) {
|
||||
log.error("getPackageBottles:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPackage(packageName: string): Promise<Partial<Package>> {
|
||||
try {
|
||||
return await withRetry(async () => {
|
||||
|
|
|
@ -326,19 +326,6 @@ export async function getAllPosts(type: string): Promise<AirtablePost[]> {
|
|||
return posts;
|
||||
}
|
||||
|
||||
export async function getPackageBottles(name: string): Promise<Bottle[]> {
|
||||
return [
|
||||
{ name, platform: "darwin", arch: "aarch64", version: "3.39.4", bytes: 123456 },
|
||||
{ name, platform: "darwin", arch: "aarch64", version: "3.40.0", bytes: 123456 },
|
||||
{ name, platform: "darwin", arch: "x86-64", version: "3.39.4", bytes: 123456 },
|
||||
{ name, platform: "darwin", arch: "x86-64", version: "3.40.0", bytes: 123456 },
|
||||
{ name, platform: "linux", arch: "aarch64", version: "3.39.4", bytes: 123456 },
|
||||
{ name, platform: "linux", arch: "aarch64", version: "3.40.0", bytes: 123456 },
|
||||
{ name, platform: "linux", arch: "x86-64", version: "3.39.4", bytes: 123456 },
|
||||
{ name, platform: "linux", arch: "x86-64", version: "3.40.0", bytes: 123456 }
|
||||
];
|
||||
}
|
||||
|
||||
export async function getPackage(packageName: string): Promise<Partial<Package>> {
|
||||
return packages.find((pkg) => pkg.full_name === packageName) || packages[0];
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
getInstalledPackages,
|
||||
installPackage,
|
||||
deletePackage,
|
||||
getPackageBottles,
|
||||
setBadgeCount,
|
||||
loadPackageCache,
|
||||
writePackageCache,
|
||||
|
@ -48,17 +47,6 @@ export default function initPackagesStore() {
|
|||
|
||||
let packagesIndex: Fuse<GUIPackage>;
|
||||
|
||||
// TODO: derive this concurrency relative to user's internet and computer performance?
|
||||
const concurrency = 3;
|
||||
const bottlesQueue = new Queue(concurrency, []);
|
||||
bottlesQueue.setProcessor(async (pkgName: string) => {
|
||||
// TODO: this api should take an architecture argument or else an architecture filter should be applied downstreawm
|
||||
const bottles = await getPackageBottles(pkgName);
|
||||
if (bottles?.length) {
|
||||
updatePackage(pkgName, { bottles });
|
||||
}
|
||||
});
|
||||
|
||||
const updateAllPackages = (guiPkgs: GUIPackage[]) => {
|
||||
packageMap.update((pkgs) => {
|
||||
guiPkgs.forEach((pkg) => {
|
||||
|
@ -283,10 +271,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
}
|
||||
};
|
||||
|
||||
const fetchPackageBottles = async (pkgName: string) => {
|
||||
bottlesQueue.enqueue(pkgName);
|
||||
};
|
||||
|
||||
const deletePkg = async (pkg: GUIPackage, version: string) => {
|
||||
log.info("deleting package: ", pkg.full_name, " version: ", version);
|
||||
await deletePackage({ fullName: pkg.full_name, version });
|
||||
|
@ -336,7 +320,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
|
|||
const matchingPackages: GUIPackage[] = res.map((v) => v.item);
|
||||
return matchingPackages;
|
||||
},
|
||||
fetchPackageBottles,
|
||||
init,
|
||||
installPkg,
|
||||
uninstallPkg,
|
||||
|
@ -380,55 +363,3 @@ const setBadgeCountFromPkgs = (pkgs: Packages) => {
|
|||
log.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
type Processor = (input: string) => void;
|
||||
|
||||
// TODO: move this to a generic design pattern then to another module
|
||||
class Queue {
|
||||
private items: string[] = [];
|
||||
private processor: Processor | null = null;
|
||||
private processingCount = 0;
|
||||
private concurrency: number;
|
||||
|
||||
constructor(concurrency = 3, initialItems: string[] = []) {
|
||||
this.concurrency = concurrency;
|
||||
this.items = initialItems;
|
||||
}
|
||||
|
||||
setProcessor(processor: Processor): void {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
private async processQueue(): Promise<void> {
|
||||
if (this.processingCount >= this.concurrency || this.items.length === 0 || !this.processor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = this.dequeue();
|
||||
if (item !== undefined) {
|
||||
this.processingCount++;
|
||||
Promise.resolve(this.processor(item))
|
||||
.then(() => {
|
||||
this.processingCount--;
|
||||
this.processQueue();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(`Error processing item: ${error}`);
|
||||
this.processingCount--;
|
||||
this.processQueue();
|
||||
});
|
||||
|
||||
// Start processing the next item(s) if concurrency allows
|
||||
this.processQueue();
|
||||
}
|
||||
}
|
||||
|
||||
enqueue(item: string): void {
|
||||
this.items.push(item);
|
||||
this.processQueue();
|
||||
}
|
||||
|
||||
dequeue(): string | undefined {
|
||||
return this.items.shift();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue