Skip to content

Commit a0da281

Browse files
committed
remove unused task, use only dependency count
1 parent 07c82c2 commit a0da281

File tree

1 file changed

+5
-57
lines changed

1 file changed

+5
-57
lines changed

frontend/src/features/archived-items/item-dependency-list/item-dependency-list.ts

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { localized, msg } from "@lit/localize";
2-
import { Task } from "@lit/task";
32
import { html, nothing, unsafeCSS } from "lit";
43
import { customElement, property } from "lit/decorators.js";
54
import { repeat } from "lit/directives/repeat.js";
6-
import queryString from "query-string";
75

86
import { collectionStatusIcon } from "../templates/collection-status-icon";
97

@@ -14,17 +12,12 @@ import { dedupeIcon } from "@/features/collections/templates/dedupe-icon";
1412
import { dedupeStatusText } from "@/features/collections/templates/dedupe-status-text";
1513
import type { ArchivedItemSectionName } from "@/pages/org/archived-item-detail/archived-item-detail";
1614
import { OrgTab, WorkflowTab } from "@/routes";
17-
import type { APIPaginatedList } from "@/types/api";
1815
import type { ArchivedItem } from "@/types/crawler";
1916
import { isCrawl, renderName } from "@/utils/crawler";
2017
import { pluralOf } from "@/utils/pluralize";
2118

2219
const styles = unsafeCSS(stylesheet);
2320

24-
// FIXME Sometimes the API returns circular dependencies
25-
const dependenciesWithoutSelf = (item: ArchivedItem) =>
26-
item.requiresCrawls.filter((id) => id !== item.id);
27-
2821
@customElement("btrix-item-dependency-list")
2922
@localized()
3023
export class ItemDependencyList extends BtrixElement {
@@ -43,51 +36,6 @@ export class ItemDependencyList extends BtrixElement {
4336
ArchivedItem | undefined
4437
>();
4538

46-
private readonly dependenciesTask = new Task(this, {
47-
task: async ([items], { signal }) => {
48-
if (!items?.length) return;
49-
50-
const itemsMap = new Map(items.map((item) => [item.id, item]));
51-
const newIds: string[] = [];
52-
53-
items.forEach((item) => {
54-
dependenciesWithoutSelf(item).forEach((id) => {
55-
if (!this.dependenciesMap.get(id)) {
56-
const cachedItem = itemsMap.get(id);
57-
if (cachedItem) {
58-
this.dependenciesMap.set(id, cachedItem);
59-
} else {
60-
newIds.push(id);
61-
}
62-
}
63-
});
64-
});
65-
66-
if (!newIds.length) return;
67-
68-
const query = queryString.stringify(
69-
{
70-
ids: newIds,
71-
},
72-
{
73-
arrayFormat: "none",
74-
},
75-
);
76-
77-
const { items: dependencies } = await this.api.fetch<
78-
APIPaginatedList<ArchivedItem>
79-
>(`/orgs/${this.orgId}/all-crawls?${query}`, { signal });
80-
81-
newIds.forEach((id) => {
82-
this.dependenciesMap.set(
83-
id,
84-
dependencies.find((item) => item.id === id),
85-
);
86-
});
87-
},
88-
args: () => [this.items] as const,
89-
});
90-
9139
disconnectedCallback(): void {
9240
this.timerIds.forEach(window.clearTimeout);
9341
super.disconnectedCallback();
@@ -143,7 +91,7 @@ export class ItemDependencyList extends BtrixElement {
14391
};
14492

14593
private readonly renderContent = (item: ArchivedItem) => {
146-
const dependencies = dependenciesWithoutSelf(item);
94+
const numDependencies = item.requiresCrawls.length;
14795
const crawled = isCrawl(item);
14896
const collectionId = this.collectionId;
14997

@@ -177,20 +125,20 @@ export class ItemDependencyList extends BtrixElement {
177125
<sl-tooltip
178126
content=${dedupeStatusText(
179127
item.requiredByCrawls.length,
180-
dependencies.length,
128+
numDependencies,
181129
)}
182130
placement="left"
183131
hoist
184132
>
185133
${
186-
dependencies.length
134+
numDependencies
187135
? html`
188136
${dedupeIcon({
189137
hasDependencies: true,
190138
hasDependents: !!item.requiredByCrawls.length,
191139
})}
192-
${this.localize.number(dependencies.length)}
193-
${pluralOf("dependencies", dependencies.length)}
140+
${this.localize.number(numDependencies)}
141+
${pluralOf("dependencies", numDependencies)}
194142
`
195143
: nothing
196144
}

0 commit comments

Comments
 (0)