|
8 | 8 | getInstalledPackages, |
9 | 9 | installPackage, |
10 | 10 | deletePackage, |
11 | | - getPackageBottles, |
12 | 11 | setBadgeCount, |
13 | 12 | loadPackageCache, |
14 | 13 | writePackageCache, |
@@ -48,17 +47,6 @@ export default function initPackagesStore() { |
48 | 47 |
|
49 | 48 | let packagesIndex: Fuse<GUIPackage>; |
50 | 49 |
|
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 | | - |
62 | 50 | const updateAllPackages = (guiPkgs: GUIPackage[]) => { |
63 | 51 | packageMap.update((pkgs) => { |
64 | 52 | guiPkgs.forEach((pkg) => { |
@@ -283,10 +271,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}). |
283 | 271 | } |
284 | 272 | }; |
285 | 273 |
|
286 | | - const fetchPackageBottles = async (pkgName: string) => { |
287 | | - bottlesQueue.enqueue(pkgName); |
288 | | - }; |
289 | | - |
290 | 274 | const deletePkg = async (pkg: GUIPackage, version: string) => { |
291 | 275 | log.info("deleting package: ", pkg.full_name, " version: ", version); |
292 | 276 | await deletePackage({ fullName: pkg.full_name, version }); |
@@ -336,7 +320,6 @@ To read more about this package go to [${guiPkg.homepage}](${guiPkg.homepage}). |
336 | 320 | const matchingPackages: GUIPackage[] = res.map((v) => v.item); |
337 | 321 | return matchingPackages; |
338 | 322 | }, |
339 | | - fetchPackageBottles, |
340 | 323 | init, |
341 | 324 | installPkg, |
342 | 325 | uninstallPkg, |
@@ -380,55 +363,3 @@ const setBadgeCountFromPkgs = (pkgs: Packages) => { |
380 | 363 | log.error(error); |
381 | 364 | } |
382 | 365 | }; |
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