Skip to content

Commit 59a9bdf

Browse files
committed
use cache to initially show directory listings in more cases
1 parent da566eb commit 59a9bdf

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

src/packages/frontend/project/explorer/file-listing/file-listing.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ export const FileListing: React.FC<Props> = ({
279279
>
280280
<FormattedMessage
281281
id="project.explorer.file-listing.stale-warning"
282-
defaultMessage={`Showing stale directory listing
283-
{is_missing, select, true {<b>missing {missing} files</b>} other {}}.
282+
defaultMessage={`Showing stale directory listing{is_missing, select, true {<b> missing {missing} files</b>} other {}}.
284283
To update the directory listing <a>start this project</a>.`}
285284
values={{
286285
is_missing: missing > 0,

src/packages/frontend/project_actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,8 @@ export class ProjectActions extends Actions<ProjectStoreState> {
14961496
page_number: 0,
14971497
most_recent_file_click: undefined,
14981498
});
1499-
this.fetch_directory_listing({ path });
1499+
1500+
store.get_listings().watch(path, true);
15001501
};
15011502

15021503
setComputeServerId = (compute_server_id: number) => {
@@ -1556,9 +1557,9 @@ export class ProjectActions extends Actions<ProjectStoreState> {
15561557

15571558
// Update the directory listing cache for the given path.
15581559
// Uses current path if path not provided.
1559-
async fetch_directory_listing(opts?): Promise<void> {
1560+
fetch_directory_listing = async (opts?): Promise<void> => {
15601561
await fetchDirectoryListing(this, opts);
1561-
}
1562+
};
15621563

15631564
public async fetch_directory_listing_directly(
15641565
path: string,

src/packages/frontend/project_store.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -616,33 +616,45 @@ export class ProjectStore extends Store<ProjectStoreState> {
616616
let directory_listings_for_server =
617617
this.getIn(["directory_listings", computeServerId]) ??
618618
immutable.Map();
619+
620+
const missing: string[] = [];
619621
for (const path of paths) {
620-
let files;
621622
if (listingsTable.getMissing(path)) {
623+
missing.push(path);
624+
}
625+
const files = await listingsTable.getForStore(path);
626+
directory_listings_for_server = directory_listings_for_server.set(
627+
path,
628+
files,
629+
);
630+
}
631+
const f = () => {
632+
const actions = redux.getProjectActions(this.project_id);
633+
const directory_listings = this.get("directory_listings").set(
634+
computeServerId,
635+
directory_listings_for_server,
636+
);
637+
actions.setState({ directory_listings });
638+
};
639+
f();
640+
641+
if (missing.length > 0) {
642+
for (const path of missing) {
622643
try {
623-
files = immutable.fromJS(
644+
const files = immutable.fromJS(
624645
await listingsTable.getListingDirectly(path),
625646
);
626-
} catch (err) {
627-
console.log(
628-
`WARNING: temporary problem getting directory listing -- ${err}`,
647+
directory_listings_for_server = directory_listings_for_server.set(
648+
path,
649+
files,
629650
);
630-
files = await listingsTable.getForStore(path);
651+
} catch {
652+
// happens if e.g., the project is not running
653+
continue;
631654
}
632-
} else {
633-
files = await listingsTable.getForStore(path);
634655
}
635-
directory_listings_for_server = directory_listings_for_server.set(
636-
path,
637-
files,
638-
);
656+
f();
639657
}
640-
const actions = redux.getProjectActions(this.project_id);
641-
const directory_listings = this.get("directory_listings").set(
642-
computeServerId,
643-
directory_listings_for_server,
644-
);
645-
actions.setState({ directory_listings });
646658
});
647659
}
648660
if (this.listings[computeServerId] == null) {

0 commit comments

Comments
 (0)