Skip to content

[prebuilds] make sure prebuild and branch commits are the same #10661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions components/dashboard/src/projects/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function () {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isLoadingBranches, setIsLoadingBranches] = useState<boolean>(false);
const [branches, setBranches] = useState<Project.BranchDetails[]>([]);
const [lastPrebuilds, setLastPrebuilds] = useState<Map<string, PrebuildWithStatus | undefined>>(new Map());
const [prebuilds, setPrebuilds] = useState<Map<string, PrebuildWithStatus | undefined>>(new Map());
const [prebuildLoaders] = useState<Set<string>>(new Set());

const [searchFilter, setSearchFilter] = useState<string | undefined>();
Expand Down Expand Up @@ -122,31 +122,31 @@ export default function () {
});
};

const lastPrebuild = (branch: Project.BranchDetails) => {
const lastPrebuild = lastPrebuilds.get(branch.name);
if (!lastPrebuild) {
const matchingPrebuild = (branch: Project.BranchDetails) => {
const matchingPrebuild = prebuilds.get(branch.name);
if (!matchingPrebuild) {
// do not await here.
loadPrebuild(branch);
}
return lastPrebuild;
return matchingPrebuild;
};

const loadPrebuild = async (branch: Project.BranchDetails) => {
if (prebuildLoaders.has(branch.name) || lastPrebuilds.has(branch.name)) {
// `lastPrebuilds.has(branch.name)` will be true even if loading finished with no prebuild found.
if (prebuildLoaders.has(branch.name) || prebuilds.has(branch.name)) {
// `prebuilds.has(branch.name)` will be true even if loading finished with no prebuild found.
// TODO(at): this need to be revised once prebuild events are integrated
return;
}
if (!project) {
return;
}
prebuildLoaders.add(branch.name);
const lastPrebuild = await getGitpodService().server.findPrebuilds({
const branchPrebuilds = await getGitpodService().server.findPrebuilds({
projectId: project.id,
branch: branch.name,
latest: true,
});
setLastPrebuilds((prev) => new Map(prev).set(branch.name, lastPrebuild[0]));
setPrebuilds((prev) => new Map(prev).set(branch.name, branchPrebuilds[0]));
prebuildLoaders.delete(branch.name);
};

Expand Down Expand Up @@ -269,8 +269,10 @@ export default function () {
.filter(filter)
.slice(0, 10)
.map((branch, index) => {
const prebuild = lastPrebuild(branch); // this might lazily trigger fetching of prebuild details

let prebuild = matchingPrebuild(branch); // this might lazily trigger fetching of prebuild details
if (prebuild && prebuild.info.changeHash !== branch.changeHash) {
prebuild = undefined;
}
const avatar = branch.changeAuthorAvatar && (
<img
className="rounded-full w-4 h-4 inline-block align-text-bottom mr-2 overflow-hidden"
Expand Down Expand Up @@ -360,7 +362,8 @@ export default function () {
title: "Cancel Prebuild",
customFontStyle:
"text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300",
onClick: () => cancelPrebuild(prebuild.info.id),
onClick: () =>
prebuild && cancelPrebuild(prebuild.info.id),
},
]
: []
Expand Down