Skip to content

Commit f569ca3

Browse files
authored
avoid reloading users on every user change (#5010)
SDCP-1037
1 parent 78b7988 commit f569ca3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

scripts/core/helpers/data-provider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ export class DataProvider<T extends IBaseRestApiResponse> implements IDataProvid
3232
private scheduleUpdate: () => void;
3333
private cache: IRestApiResponse<T>;
3434

35-
constructor(requestFactory: IRequestFactory, responseHandler: IResponseHandler<T>, listenTo: IListenTo) {
35+
constructor(
36+
requestFactory: IRequestFactory,
37+
responseHandler: IResponseHandler<T>,
38+
listenTo: IListenTo,
39+
updateTimeout?: number,
40+
) {
3641
this.requestFactory = requestFactory;
3742
this.responseHandler = responseHandler;
3843
this.listenTo = listenTo || {};
44+
this.updateTimeout = updateTimeout ?? this.updateTimeout;
3945
this.scheduleUpdate = debounce(() => this.fetch(), this.updateTimeout);
4046

4147
// init

scripts/data-store.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DataStore {
1111
public contentProfiles: OrderedMap<IContentProfile['_id'], IContentProfile>;
1212
public users: OrderedMap<IUser['_id'], IUser>;
1313

14+
private initializePromise: Promise<any>;
15+
1416
constructor() {
1517
this.contentProfiles = OrderedMap();
1618
}
@@ -81,13 +83,22 @@ class DataStore {
8183

8284
resolveOnce();
8385
},
84-
{'users': true},
86+
{'users': {
87+
create: true,
88+
delete: true,
89+
update: ['display_name'],
90+
}},
91+
2000,
8592
);
8693
});
8794
}
8895

8996
initialize() {
90-
return Promise.all([this.loadContentProfiles(), this.loadUsers()]);
97+
if (this.initializePromise == null) {
98+
this.initializePromise = Promise.all([this.loadContentProfiles(), this.loadUsers()]);
99+
}
100+
101+
return this.initializePromise;
91102
}
92103
}
93104

0 commit comments

Comments
 (0)