Skip to content

Commit d6e1866

Browse files
authored
undo limit to fetch the first 100 user repos for New Workspace – EXP-554 (#18644)
* undo limit to fetch the first 100 user repos for New Workspace this reverts 2f2b1ab effectively * don't call getSuggestedContextURLs on each setUser call * Always cap the respository search results to be rendered on New Workspace
1 parent 86fa3ba commit d6e1866

File tree

3 files changed

+47
-44
lines changed

3 files changed

+47
-44
lines changed

components/dashboard/src/components/RepositoryFinder.tsx

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,44 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
4040

4141
const getElements = useCallback(
4242
(searchString: string) => {
43-
const result = [...suggestedContextURLs];
43+
let result: string[];
4444
searchString = searchString.trim();
45-
try {
46-
// If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here.
47-
new URL(searchString);
48-
if (!result.includes(searchString)) {
49-
result.push(searchString);
45+
if (searchString.length > 1) {
46+
result = suggestedContextURLs.filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1);
47+
if (result.length > 200) {
48+
result = result.slice(0, 200);
5049
}
51-
} catch {}
52-
return result
53-
.filter((e) => e.toLowerCase().indexOf(searchString.toLowerCase()) !== -1)
54-
.map(
55-
(e) =>
56-
({
57-
id: e,
58-
element: (
59-
<div className="flex-col ml-1 mt-1 flex-grow">
60-
<div className="flex">
61-
<div className="text-gray-700 dark:text-gray-300 font-semibold">
62-
{stripOffProtocol(e)}
63-
</div>
64-
<div className="ml-1 text-gray-400">{}</div>
50+
if (result.length === 0) {
51+
try {
52+
// If the searchString is a URL, and it's not present in the proposed results, "artificially" add it here.
53+
new URL(searchString);
54+
if (!suggestedContextURLs.includes(searchString)) {
55+
result.push(searchString);
56+
}
57+
} catch {}
58+
}
59+
} else {
60+
result = suggestedContextURLs.slice(0, 200);
61+
}
62+
63+
return result.map(
64+
(e) =>
65+
({
66+
id: e,
67+
element: (
68+
<div className="flex-col ml-1 mt-1 flex-grow">
69+
<div className="flex">
70+
<div className="text-gray-700 dark:text-gray-300 font-semibold">
71+
{stripOffProtocol(e)}
6572
</div>
66-
<div className="flex text-xs text-gray-400">{}</div>
73+
<div className="ml-1 text-gray-400">{}</div>
6774
</div>
68-
),
69-
isSelectable: true,
70-
} as DropDown2Element),
71-
);
75+
<div className="flex text-xs text-gray-400">{}</div>
76+
</div>
77+
),
78+
isSelectable: true,
79+
} as DropDown2Element),
80+
);
7281
},
7382
[suggestedContextURLs],
7483
);
@@ -131,11 +140,3 @@ function saveSearchData(searchData: string[]): void {
131140
console.warn("Could not save search data into local storage", error);
132141
}
133142
}
134-
135-
export function refreshSearchData() {
136-
getGitpodService()
137-
.server.getSuggestedContextURLs()
138-
.then((urls) => {
139-
saveSearchData(urls);
140-
});
141-
}

components/dashboard/src/hooks/use-user-loader.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

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

2120
// For now, we're using the user context to store the user, but letting react-query handle the loading
2221
// In the future, we should remove the user context and use react-query to access the user
23-
const { isLoading } = useQuery({
22+
const userQuery = useQuery({
2423
queryKey: noPersistence(["current-user"]),
2524
queryFn: async () => {
2625
const user = await getGitpodService().server.getLoggedInUser();
@@ -41,14 +40,18 @@ export const useUserLoader = () => {
4140
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
4241
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
4342
staleTime: 1000 * 60 * 60 * 1, // 1 hour
44-
onSuccess: (loadedUser) => {
45-
setUser(loadedUser);
46-
refreshSearchData();
47-
},
43+
4844
onSettled: (loadedUser) => {
4945
trackLocation(!!loadedUser);
5046
},
5147
});
5248

53-
return { user, loading: isLoading };
49+
// onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
50+
useEffect(() => {
51+
if (userQuery.data) {
52+
setUser(userQuery.data);
53+
}
54+
}, [userQuery.data, setUser]);
55+
56+
return { user, loading: userQuery.isLoading };
5457
};

components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
146146

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

0 commit comments

Comments
 (0)