Skip to content

undo limit to fetch the first 100 user repos for New Workspace – EXP-554 #18644

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 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
67 changes: 34 additions & 33 deletions components/dashboard/src/components/RepositoryFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,44 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {

const getElements = useCallback(
(searchString: string) => {
const result = [...suggestedContextURLs];
let result: string[];
searchString = searchString.trim();
try {
// If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here.
new URL(searchString);
if (!result.includes(searchString)) {
result.push(searchString);
if (searchString.length > 1) {
result = suggestedContextURLs.filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1);
if (result.length > 200) {
result = result.slice(0, 200);
}
} catch {}
return result
.filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1)
.map(
(e) =>
({
id: e,
element: (
<div className="flex-col ml-1 mt-1 flex-grow">
<div className="flex">
<div className="text-gray-700 dark:text-gray-300 font-semibold">
{stripOffProtocol(e)}
</div>
<div className="ml-1 text-gray-400">{}</div>
if (result.length === 0) {
try {
// If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here.
new URL(searchString);
if (!suggestedContextURLs.includes(searchString)) {
result.push(searchString);
}
} catch {}
}
} else {
result = suggestedContextURLs.slice(0, 200);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this, I was wondering if we could add a trailing element which indicates that this list is truncated.

}

return result.map(
(e) =>
({
id: e,
element: (
<div className="flex-col ml-1 mt-1 flex-grow">
<div className="flex">
<div className="text-gray-700 dark:text-gray-300 font-semibold">
{stripOffProtocol(e)}
</div>
<div className="flex text-xs text-gray-400">{}</div>
<div className="ml-1 text-gray-400">{}</div>
</div>
),
isSelectable: true,
} as DropDown2Element),
);
<div className="flex text-xs text-gray-400">{}</div>
</div>
),
isSelectable: true,
} as DropDown2Element),
);
},
[suggestedContextURLs],
);
Expand Down Expand Up @@ -131,11 +140,3 @@ function saveSearchData(searchData: string[]): void {
console.warn("Could not save search data into local storage", error);
}
}

export function refreshSearchData() {
getGitpodService()
.server.getSuggestedContextURLs()
.then((urls) => {
saveSearchData(urls);
});
}
19 changes: 11 additions & 8 deletions components/dashboard/src/hooks/use-user-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useContext } from "react";
import { useContext, useEffect } from "react";
import { UserContext } from "../user-context";
import { getGitpodService } from "../service/service";
import { trackLocation } from "../Analytics";
import { refreshSearchData } from "../components/RepositoryFinder";
import { useQuery } from "@tanstack/react-query";
import { noPersistence } from "../data/setup";
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
Expand All @@ -20,7 +19,7 @@ export const useUserLoader = () => {

// For now, we're using the user context to store the user, but letting react-query handle the loading
// In the future, we should remove the user context and use react-query to access the user
const { isLoading } = useQuery({
const userQuery = useQuery({
queryKey: noPersistence(["current-user"]),
queryFn: async () => {
const user = await getGitpodService().server.getLoggedInUser();
Expand All @@ -41,14 +40,18 @@ export const useUserLoader = () => {
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
staleTime: 1000 * 60 * 60 * 1, // 1 hour
onSuccess: (loadedUser) => {
setUser(loadedUser);
refreshSearchData();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svenefftinge, maybe you recall why this was introduced?
We've noticed getSuggestedContextURLs was called 3x on load of /new. Explicitly updating on setUser seems to be less obvious, but maybe there was some reason to introduce this? git history shows that there were many changes related to the transition from contexts holding/updating data to usage of query, and I wonder if this is a left-over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does RepositoryFinder depend on any user properties that it should be retriggered? if not it should not be here? It looks rather strange way of doing, we would provide user state as a dependency to RepositoryFinder if we want to do it properly? cc @selfcontained

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! πŸ€·πŸ»β€β™‚οΈ
Maybe if you're pasting in a repository URL of a SCM provider you did not authorized with, and the context resolution fails, which will render the Authorize with provider action? But even if that's the case, and we'd call setUser on a success event, we should try to refresh search data from there, and not do it on every update, including the initial one.
I'll try to reproduce, and see how that's behaving.

},

onSettled: (loadedUser) => {
trackLocation(!!loadedUser);
},
});

return { user, loading: isLoading };
// onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
useEffect(() => {
if (userQuery.data) {
setUser(userQuery.data);
}
}, [userQuery.data, setUser]);

return { user, loading: userQuery.isLoading };
};
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {

async getUserRepos(user: User): Promise<string[]> {
try {
// TODO: See if there's another api we could use here, such as recent repos for the user
// Only grab one page of up to 100 repos
const repos = await this.api.getRepos(user, { limit: 100, maxPages: 1, permission: "REPO_READ" });
// TODO: implement incremental search
const repos = await this.api.getRepos(user, { maxPages: 10, permission: "REPO_READ" });
const result: string[] = [];
repos.forEach((r) => {
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href;
Expand Down