Skip to content

Commit 24900aa

Browse files
babyleafymeta-codesync[bot]
authored andcommitted
Integrate recommended bookmarks graphql with isl-server
Summary: This diff uses the new Ent based generalized mapping of recommended bookmarks. This has several benefits including reduced latency at startup, as the server now determines the recommended bookmark names instead of the client (instead of back and forth messages). We also benefit from decouple onboarding of new bookmarks/users from ISL releases. See [this doc](https://docs.google.com/document/d/17PpbY_fIuuNpRIgdeFVYFZGBtbNFJzuLBqbBUpoMlcU/edit?usp=sharing) for reference. Still, some improvements can be made by sending over recommended bookmarks with the first smartlog commits fetch. However this does have drawbacks of making the initial fetch a bit slower, and can be considered in a future diff. Reviewed By: evangrayk Differential Revision: D86217928 fbshipit-source-id: 258cce7fc08917f112d911e069a9220d19d824e7
1 parent 8fc56c8 commit 24900aa

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

addons/isl-server/src/Repository.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ export class Repository {
171171
/**
172172
* Recommended remote bookmarks to be include in batched `log` fetch.
173173
* If a bookmark is not in the subscriptions list yet, then it will be pulled explicitly.
174+
* Undefined means not yet fetched.
174175
*/
175-
public recommendedBookmarks: Array<string> = [];
176+
public recommendedBookmarks: Array<string> | undefined;
176177

177178
/**
178179
* The context used when the repository was created.
@@ -953,6 +954,7 @@ export class Repository {
953954
const fetchStartTimestamp = Date.now();
954955
try {
955956
this.smartlogCommitsBeginFetchingEmitter.emit('start');
957+
956958
const visibleCommitDayRange = this.visibleCommitRanges[this.currentVisibleCommitRangeIndex];
957959

958960
const primaryRevset = '(interestingbookmarks() + heads(draft()))';
@@ -969,7 +971,7 @@ export class Repository {
969971
'.', // always include wdir parent
970972
// stable locations hashes may be newer than the repo has, wrap in `present()` to only include if available.
971973
...this.stableLocations.map(location => `present(${location.hash})`),
972-
...this.recommendedBookmarks.map(bookmark => `present(${bookmark})`),
974+
...(this.recommendedBookmarks ?? []).map(bookmark => `present(${bookmark})`),
973975
...(this.fullRepoBranchModule?.genRevset() ?? []),
974976
]
975977
.filter(notEmpty)
@@ -1025,8 +1027,23 @@ export class Repository {
10251027
}
10261028
});
10271029

1028-
async pullRecommendedBookmarks(ctx: RepositoryContext) {
1029-
if (!this.recommendedBookmarks.length) {
1030+
public async fetchAndSetRecommendedBookmarks(onFetched?: (bookmarks: Array<string>) => void) {
1031+
if (!Internal.getRecommendedBookmarks) {
1032+
return;
1033+
}
1034+
1035+
try {
1036+
const bookmarks = await Internal.getRecommendedBookmarks(this.initialConnectionContext);
1037+
onFetched?.((this.recommendedBookmarks = bookmarks.map((b: string) => `remote/${b}`)));
1038+
void this.pullRecommendedBookmarks(this.initialConnectionContext);
1039+
} catch (err) {
1040+
this.initialConnectionContext.logger.error('Error fetching recommended bookmarks:', err);
1041+
void onFetched?.([]);
1042+
}
1043+
}
1044+
1045+
async pullRecommendedBookmarks(ctx: RepositoryContext): Promise<void> {
1046+
if (!this.recommendedBookmarks || !this.recommendedBookmarks.length) {
10301047
return;
10311048
}
10321049

@@ -1042,7 +1059,7 @@ export class Repository {
10421059
);
10431060

10441061
if (missingBookmarks.length > 0) {
1045-
// ISL prefixes bookmarks with remote/, so we need to strip this to pull the remote names
1062+
// We need to strip to pull the remote names
10461063
const missingRemoteNames = missingBookmarks.map(bookmark =>
10471064
bookmark.replace(/^remote\//, ''),
10481065
);

addons/isl-server/src/ServerToClientAPI.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ export default class ServerToClientAPI {
388388
const disposables: Array<Disposable> = [];
389389
// send changes as they come from file watcher
390390
disposables.push(repo.subscribeToSmartlogCommitsChanges(postSmartlogCommits));
391-
// trigger a fetch on startup
391+
392+
// trigger fetches on startup
393+
repo.fetchAndSetRecommendedBookmarks(bookmarks => {
394+
this.postMessage({type: 'fetchedRecommendedBookmarks', bookmarks});
395+
});
392396
repo.fetchSmartlogCommits();
393397

394398
disposables.push(
@@ -604,6 +608,9 @@ export default class ServerToClientAPI {
604608
}
605609
case 'refresh': {
606610
logger?.log('refresh requested');
611+
repo.fetchAndSetRecommendedBookmarks(bookmarks => {
612+
this.postMessage({type: 'fetchedRecommendedBookmarks', bookmarks});
613+
});
607614
repo.fetchSmartlogCommits();
608615
repo.fetchUncommittedChanges();
609616
repo.fetchSubmoduleMap();

addons/isl/src/BookmarksData.tsx

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import type {StableLocationData} from './types';
1010
import {atom} from 'jotai';
1111
import {tracker} from './analytics';
1212
import serverAPI from './ClientToServerAPI';
13-
import {Internal} from './Internal';
14-
import {lazyAtom, localStorageBackedAtom, readAtom, writeAtom} from './jotaiUtils';
13+
import {localStorageBackedAtom, readAtom, writeAtom} from './jotaiUtils';
1514
import {latestCommits} from './serverAPIState';
1615
import {registerDisposable} from './utils';
1716

@@ -81,6 +80,22 @@ registerDisposable(
8180
);
8281
fetchStableLocations(); // fetch on startup
8382

83+
registerDisposable(
84+
serverAPI,
85+
serverAPI.onMessageOfType('fetchedRecommendedBookmarks', data => {
86+
writeAtom(recommendedBookmarksAtom, new Set(data.bookmarks));
87+
88+
const bookmarksData = readAtom(bookmarksDataStorage);
89+
tracker.track('RecommendedBookmarksStatus', {
90+
extras: {
91+
enabled: bookmarksData.useRecommendedBookmark ?? false,
92+
recommendedBookmarks: data.bookmarks,
93+
},
94+
});
95+
}),
96+
import.meta.hot,
97+
);
98+
8499
export function fetchStableLocations() {
85100
const data = readAtom(bookmarksDataStorage);
86101
const additionalStables = data.additionalStables ?? [];
@@ -95,15 +110,6 @@ export const remoteBookmarks = atom(get => {
95110
return commits.flatMap(commit => commit.remoteBookmarks);
96111
});
97112

98-
function fetchRecommendedBookmarks(recommendedBookmarks: Array<string>) {
99-
if (recommendedBookmarks) {
100-
serverAPI.postMessage({
101-
type: 'fetchRecommendedBookmarks',
102-
recommendedBookmarks,
103-
});
104-
}
105-
}
106-
107113
/**
108114
* For determining if reminders to use recommended bookmarks should be shown
109115
*/
@@ -123,26 +129,7 @@ export const recommendedBookmarksOnboarding = localStorageBackedAtom<boolean>(
123129
true,
124130
);
125131

126-
export const recommendedBookmarksAtom = lazyAtom(async _get => {
127-
const recommendedBookmarks = await (Internal.getRecommendedBookmarks?.() ??
128-
Promise.resolve(new Set<string>()));
129-
130-
// Fetch the recommended bookmarks from server on startup
131-
if (recommendedBookmarks.size > 0) {
132-
fetchRecommendedBookmarks(Array.from(recommendedBookmarks));
133-
134-
// Track recommended bookmarks to approximate adoption
135-
const bookmarksData = readAtom(bookmarksDataStorage);
136-
tracker.track('RecommendedBookmarksStatus', {
137-
extras: {
138-
enabled: bookmarksData.useRecommendedBookmark ?? false,
139-
recommendedBookmarks: Array.from(recommendedBookmarks),
140-
},
141-
});
142-
}
143-
144-
return recommendedBookmarks;
145-
}, new Set<string>());
132+
export const recommendedBookmarksAtom = atom<Set<string>>(new Set<string>());
146133

147134
/** Checks if recommended bookmarks are available in remoteBookmarks */
148135
export const recommendedBookmarksAvailableAtom = atom(get => {

addons/isl/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ export type ServerToClientMessage =
11241124
| {type: 'confirmedLand'; result: Result<undefined>}
11251125
| {type: 'fetchedCommitCloudState'; state: Result<CommitCloudSyncState>}
11261126
| {type: 'fetchedStables'; stables: StableLocationData}
1127+
| {type: 'fetchedRecommendedBookmarks'; bookmarks: Array<string>}
11271128
| {type: 'fetchedStableLocationAutocompleteOptions'; result: Result<Array<TypeaheadResult>>}
11281129
| {type: 'renderedMarkup'; html: string; id: number}
11291130
| {type: 'gotSuggestedReviewers'; reviewers: Array<string>; key: string}

0 commit comments

Comments
 (0)