Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit ae02ff0

Browse files
getneilneil molina
andauthored
#554 remove unused data initialization (#562)
Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
1 parent b7e45f0 commit ae02ff0

5 files changed

Lines changed: 0 additions & 105 deletions

File tree

modules/desktop/src/components/packages/package.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
44
import { PackageStates, type GUIPackage } from "$libs/types";
55
import { packagesStore } from "$libs/stores";
6-
import { onMount } from "svelte";
76
import PackageCard from "$components/package-card/package-card.svelte";
87
98
export let tab = "all";
109
export let pkg: GUIPackage;
1110
export let layout: "bottom" | "left" | "right" = "bottom";
12-
13-
onMount(() => {
14-
packagesStore.fetchPackageBottles(pkg.full_name);
15-
});
1611
</script>
1712

1813
<PackageCard

modules/desktop/src/components/search-popup-results/package-search-result.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import type { GUIPackage } from "$libs/types";
33
import { packagesStore } from "$libs/stores";
4-
import { onMount } from "svelte";
54
65
import ImgLoader from "@tea/ui/img-loader/img-loader.svelte";
76
import { goto } from "$app/navigation";
@@ -14,10 +13,6 @@
1413
1514
$: updatedPkg = $packageList.find((p) => p.full_name === pkg.full_name);
1615
17-
onMount(() => {
18-
packagesStore.fetchPackageBottles(pkg.full_name);
19-
});
20-
2116
const gotoPackagePage = () => {
2217
goto(`/packages/${pkg.slug}?tab=all`);
2318
onClose();

modules/desktop/src/libs/native-electron.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,6 @@ export async function getAllPosts(tag?: string): Promise<AirtablePost[]> {
123123
}
124124
}
125125

126-
export async function getPackageBottles(packageName: string): Promise<Bottle[]> {
127-
try {
128-
return withRetry(async () => {
129-
const pkg = await apiGet<Package>(`packages/${packageName.replaceAll("/", ":")}`);
130-
log.info(`got ${pkg?.bottles?.length || 0} bottles for ${packageName}`);
131-
return (pkg && pkg.bottles) || [];
132-
});
133-
} catch (error) {
134-
log.error("getPackageBottles:", error);
135-
return [];
136-
}
137-
}
138-
139126
export async function getPackage(packageName: string): Promise<Partial<Package>> {
140127
try {
141128
return await withRetry(async () => {

modules/desktop/src/libs/native-mock.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,6 @@ export async function getAllPosts(type: string): Promise<AirtablePost[]> {
326326
return posts;
327327
}
328328

329-
export async function getPackageBottles(name: string): Promise<Bottle[]> {
330-
return [
331-
{ name, platform: "darwin", arch: "aarch64", version: "3.39.4", bytes: 123456 },
332-
{ name, platform: "darwin", arch: "aarch64", version: "3.40.0", bytes: 123456 },
333-
{ name, platform: "darwin", arch: "x86-64", version: "3.39.4", bytes: 123456 },
334-
{ name, platform: "darwin", arch: "x86-64", version: "3.40.0", bytes: 123456 },
335-
{ name, platform: "linux", arch: "aarch64", version: "3.39.4", bytes: 123456 },
336-
{ name, platform: "linux", arch: "aarch64", version: "3.40.0", bytes: 123456 },
337-
{ name, platform: "linux", arch: "x86-64", version: "3.39.4", bytes: 123456 },
338-
{ name, platform: "linux", arch: "x86-64", version: "3.40.0", bytes: 123456 }
339-
];
340-
}
341-
342329
export async function getPackage(packageName: string): Promise<Partial<Package>> {
343330
return packages.find((pkg) => pkg.full_name === packageName) || packages[0];
344331
}

modules/desktop/src/libs/stores/pkgs.ts

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
getInstalledPackages,
99
installPackage,
1010
deletePackage,
11-
getPackageBottles,
1211
setBadgeCount,
1312
loadPackageCache,
1413
writePackageCache,
@@ -48,17 +47,6 @@ export default function initPackagesStore() {
4847

4948
let packagesIndex: Fuse<GUIPackage>;
5049

51-
// TODO: derive this concurrency relative to user's internet and computer performance?
52-
const concurrency = 3;
53-
const bottlesQueue = new Queue(concurrency, []);
54-
bottlesQueue.setProcessor(async (pkgName: string) => {
55-
// TODO: this api should take an architecture argument or else an architecture filter should be applied downstreawm
56-
const bottles = await getPackageBottles(pkgName);
57-
if (bottles?.length) {
58-
updatePackage(pkgName, { bottles });
59-
}
60-
});
61-
6250
const updateAllPackages = (guiPkgs: GUIPackage[]) => {
6351
packageMap.update((pkgs) => {
6452
guiPkgs.forEach((pkg) => {
@@ -283,10 +271,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
283271
}
284272
};
285273

286-
const fetchPackageBottles = async (pkgName: string) => {
287-
bottlesQueue.enqueue(pkgName);
288-
};
289-
290274
const deletePkg = async (pkg: GUIPackage, version: string) => {
291275
log.info("deleting package: ", pkg.full_name, " version: ", version);
292276
await deletePackage({ fullName: pkg.full_name, version });
@@ -336,7 +320,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}).
336320
const matchingPackages: GUIPackage[] = res.map((v) => v.item);
337321
return matchingPackages;
338322
},
339-
fetchPackageBottles,
340323
init,
341324
installPkg,
342325
uninstallPkg,
@@ -380,55 +363,3 @@ const setBadgeCountFromPkgs = (pkgs: Packages) => {
380363
log.error(error);
381364
}
382365
};
383-
384-
type Processor = (input: string) => void;
385-
386-
// TODO: move this to a generic design pattern then to another module
387-
class Queue {
388-
private items: string[] = [];
389-
private processor: Processor | null = null;
390-
private processingCount = 0;
391-
private concurrency: number;
392-
393-
constructor(concurrency = 3, initialItems: string[] = []) {
394-
this.concurrency = concurrency;
395-
this.items = initialItems;
396-
}
397-
398-
setProcessor(processor: Processor): void {
399-
this.processor = processor;
400-
}
401-
402-
private async processQueue(): Promise<void> {
403-
if (this.processingCount >= this.concurrency || this.items.length === 0 || !this.processor) {
404-
return;
405-
}
406-
407-
const item = this.dequeue();
408-
if (item !== undefined) {
409-
this.processingCount++;
410-
Promise.resolve(this.processor(item))
411-
.then(() => {
412-
this.processingCount--;
413-
this.processQueue();
414-
})
415-
.catch((error) => {
416-
console.error(`Error processing item: ${error}`);
417-
this.processingCount--;
418-
this.processQueue();
419-
});
420-
421-
// Start processing the next item(s) if concurrency allows
422-
this.processQueue();
423-
}
424-
}
425-
426-
enqueue(item: string): void {
427-
this.items.push(item);
428-
this.processQueue();
429-
}
430-
431-
dequeue(): string | undefined {
432-
return this.items.shift();
433-
}
434-
}

0 commit comments

Comments
 (0)