From ae02ff020a3ee1e2fd9139c550391c7bded9d61f Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 5 May 2023 15:10:43 +0800 Subject: [PATCH] #554 remove unused data initialization (#562) Co-authored-by: neil molina --- .../src/components/packages/package.svelte | 5 -- .../package-search-result.svelte | 5 -- modules/desktop/src/libs/native-electron.ts | 13 ---- modules/desktop/src/libs/native-mock.ts | 13 ---- modules/desktop/src/libs/stores/pkgs.ts | 69 ------------------- 5 files changed, 105 deletions(-) diff --git a/modules/desktop/src/components/packages/package.svelte b/modules/desktop/src/components/packages/package.svelte index 0ad777d..159fb5b 100644 --- a/modules/desktop/src/components/packages/package.svelte +++ b/modules/desktop/src/components/packages/package.svelte @@ -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); - }); 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(); diff --git a/modules/desktop/src/libs/native-electron.ts b/modules/desktop/src/libs/native-electron.ts index 4e3dd46..d52717a 100644 --- a/modules/desktop/src/libs/native-electron.ts +++ b/modules/desktop/src/libs/native-electron.ts @@ -123,19 +123,6 @@ export async function getAllPosts(tag?: string): Promise { } } -export async function getPackageBottles(packageName: string): Promise { - try { - return withRetry(async () => { - const pkg = await apiGet(`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> { try { return await withRetry(async () => { diff --git a/modules/desktop/src/libs/native-mock.ts b/modules/desktop/src/libs/native-mock.ts index 7c92af0..e516932 100644 --- a/modules/desktop/src/libs/native-mock.ts +++ b/modules/desktop/src/libs/native-mock.ts @@ -326,19 +326,6 @@ export async function getAllPosts(type: string): Promise { return posts; } -export async function getPackageBottles(name: string): Promise { - 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> { return packages.find((pkg) => pkg.full_name === packageName) || packages[0]; } diff --git a/modules/desktop/src/libs/stores/pkgs.ts b/modules/desktop/src/libs/stores/pkgs.ts index cef69de..a0aa23f 100644 --- a/modules/desktop/src/libs/stores/pkgs.ts +++ b/modules/desktop/src/libs/stores/pkgs.ts @@ -8,7 +8,6 @@ import { getInstalledPackages, installPackage, deletePackage, - getPackageBottles, setBadgeCount, loadPackageCache, writePackageCache, @@ -48,17 +47,6 @@ export default function initPackagesStore() { let packagesIndex: Fuse; - // 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 { - 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(); - } -}