Skip to content

Commit a34ddc9

Browse files
committed
Merge branch 'instance-page-cleanup' into 'master'
fix(ui): remove unnecessary request and timeout causing loop See merge request postgres-ai/database-lab!775
2 parents 55cf651 + e786a8b commit a34ddc9

File tree

7 files changed

+15
-62
lines changed

7 files changed

+15
-62
lines changed

ui/packages/platform/src/actions/actions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const Actions = Reflux.createActions([{
6464
editDbLabInstance: ASYNC_ACTION,
6565
destroyDbLabInstance: ASYNC_ACTION,
6666
resetNewDbLabInstance: {},
67-
getDbLabInstanceStatus: ASYNC_ACTION,
67+
reloadDblabInstance: ASYNC_ACTION,
6868
checkDbLabInstanceUrl: ASYNC_ACTION,
6969
downloadReportJsonFiles: ASYNC_ACTION,
7070
addOrgDomain: ASYNC_ACTION,
@@ -846,7 +846,7 @@ Actions.destroyDbLabInstance.listen(function (token, instanceId) {
846846
});
847847
});
848848

849-
Actions.getDbLabInstanceStatus.listen(function (token, instanceId) {
849+
Actions.reloadDblabInstance.listen(function (token, instanceId) {
850850
let action = this;
851851

852852
if (!api) {
@@ -857,12 +857,12 @@ Actions.getDbLabInstanceStatus.listen(function (token, instanceId) {
857857

858858
action.progressed({ instanceId: instanceId });
859859

860-
timeoutPromise(REQUEST_TIMEOUT, api.getDbLabInstanceStatus(token, instanceId))
860+
timeoutPromise(REQUEST_TIMEOUT, api.getInstance(token, instanceId))
861861
.then(result => {
862862
result.json()
863863
.then(json => {
864864
if (json) {
865-
action.completed({ data: json, instanceId: instanceId });
865+
action.completed({ data: json[0], instanceId: instanceId });
866866
} else {
867867
action.failed({ instanceId: instanceId }, new Error(
868868
'wrong_reply'));

ui/packages/platform/src/api/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,16 @@ class Api {
544544
});
545545
}
546546

547-
getDbLabInstanceStatus(token, instanceId) {
547+
getInstance(token, orgId) {
548548
let headers = {
549549
Authorization: 'Bearer ' + token
550550
};
551551

552-
return this.post(`${this.apiServer}/rpc/dblab_instance_status_refresh`, {
553-
instance_id: instanceId
552+
return this.get(`${this.apiServer}/dblab_instances`,{
553+
id: `eq.${orgId}`
554554
}, {
555-
headers: headers
556-
});
555+
headers: headers,
556+
})
557557
}
558558

559559
checkDbLabInstanceUrl(token, url, verifyToken, useTunnel) {

ui/packages/platform/src/api/instances/refreshInstance.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

ui/packages/platform/src/components/DbLabInstances/DbLabInstances.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class DbLabInstances extends Component<
250250
break
251251

252252
case 'refresh':
253-
Actions.getDbLabInstanceStatus(auth?.token, instanceId)
253+
Actions.reloadDblabInstance(auth?.token, instanceId)
254254

255255
break
256256

ui/packages/platform/src/pages/Instance/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Instance as InstancePage } from '@postgres.ai/shared/pages/Instance'
55
import { ConsoleBreadcrumbsWrapper } from 'components/ConsoleBreadcrumbs/ConsoleBreadcrumbsWrapper'
66
import { ROUTES } from 'config/routes'
77
import { getInstance } from 'api/instances/getInstance'
8-
import { refreshInstance } from 'api/instances/refreshInstance'
98
import { getSnapshots } from 'api/snapshots/getSnapshots'
109
import { destroyClone } from 'api/clones/destroyClone'
1110
import { resetClone } from 'api/clones/resetClone'
@@ -55,7 +54,6 @@ export const Instance = () => {
5554
getInstance,
5655
getSnapshots,
5756
destroyClone,
58-
refreshInstance,
5957
resetClone,
6058
getWSToken,
6159
getConfig,

ui/packages/platform/src/stores/store.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ const Store = Reflux.createStore({
13141314
};
13151315
},
13161316

1317-
onGetDbLabInstanceStatusFailed: function (data, error) {
1317+
onReloadDblabInstanceFailed: function (data, error) {
13181318
this.data.dbLabInstanceStatus.isProcessing = false;
13191319
this.data.dbLabInstanceStatus.isProcessed = true;
13201320
this.data.dbLabInstanceStatus.error = true;
@@ -1336,7 +1336,7 @@ const Store = Reflux.createStore({
13361336
this.trigger(this.data);
13371337
},
13381338

1339-
onGetDbLabInstanceStatusProgressed: function (data) {
1339+
onReloadDblabInstanceProgressed: function (data) {
13401340
this.data.dbLabInstanceStatus.isProcessing = true;
13411341
this.data.dbLabInstanceStatus.isProcessed = false;
13421342
this.data.dbLabInstanceStatus.error = false;
@@ -1358,7 +1358,7 @@ const Store = Reflux.createStore({
13581358
this.trigger(this.data);
13591359
},
13601360

1361-
onGetDbLabInstanceStatusCompleted: function (data) {
1361+
onReloadDblabInstanceCompleted: function (data) {
13621362
this.data.dbLabInstanceStatus.isProcessing = false;
13631363
this.data.dbLabInstanceStatus.errorMessage = this.getError(data.data);
13641364
this.data.dbLabInstanceStatus.error = !!this.data.dbLabInstanceStatus

ui/packages/shared/pages/Instance/stores/Main.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { Config } from '@postgres.ai/shared/types/api/entities/config'
1212
import { GetConfig } from '@postgres.ai/shared/types/api/endpoints/getConfig'
1313
import { UpdateConfig } from '@postgres.ai/shared/types/api/endpoints/updateConfig'
1414
import { TestDbSource } from '@postgres.ai/shared/types/api/endpoints/testDbSource'
15-
import { RefreshInstance } from '@postgres.ai/shared/types/api/endpoints/refreshInstance'
1615
import { DestroyClone } from '@postgres.ai/shared/types/api/endpoints/destroyClone'
1716
import { ResetClone } from '@postgres.ai/shared/types/api/endpoints/resetClone'
1817
import { GetWSToken } from '@postgres.ai/shared/types/api/endpoints/getWSToken'
@@ -26,14 +25,11 @@ import { GetInstanceRetrieval } from '@postgres.ai/shared/types/api/endpoints/ge
2625
import { InstanceRetrievalType } from '@postgres.ai/shared/types/api/entities/instanceRetrieval'
2726
import { GetEngine } from '@postgres.ai/shared/types/api/endpoints/getEngine'
2827

29-
const POLLING_TIME = 2000
30-
3128
const UNSTABLE_CLONE_STATUS_CODES = ['CREATING', 'RESETTING', 'DELETING']
3229

3330
export type Api = {
3431
getInstance: GetInstance
3532
getSnapshots: GetSnapshots
36-
refreshInstance?: RefreshInstance
3733
destroyClone: DestroyClone
3834
resetClone: ResetClone
3935
getWSToken: GetWSToken
@@ -62,7 +58,6 @@ export class MainStore {
6258
getFullConfigError: string | null = null
6359

6460
unstableClones = new Set<string>()
65-
private updateInstanceTimeoutId: number | null = null
6661

6762
readonly snapshots: SnapshotsStore
6863

@@ -125,16 +120,10 @@ export class MainStore {
125120
return !!response
126121
}
127122

128-
private loadInstance = async (
129-
instanceId: string,
130-
updateUnstableClones = true,
131-
) => {
123+
private loadInstance = async (instanceId: string) => {
132124
this.instanceError = null
133125
this.isLoadingInstance = true
134126

135-
if (this.api.refreshInstance)
136-
await this.api.refreshInstance({ instanceId: instanceId })
137-
138127
const { response, error } = await this.api.getInstance({
139128
instanceId: instanceId,
140129
})
@@ -160,9 +149,6 @@ export class MainStore {
160149
})
161150

162151
this.unstableClones = unstableClones
163-
164-
if (this.unstableClones.size && updateUnstableClones)
165-
this.liveUpdateInstance()
166152
}
167153

168154
if (error)
@@ -273,20 +259,13 @@ export class MainStore {
273259
}
274260

275261
private liveUpdateInstance = async () => {
276-
if (this.updateInstanceTimeoutId)
277-
window.clearTimeout(this.updateInstanceTimeoutId)
278262
if (!this.unstableClones.size) return
279263
if (!this.instance) return
280264

281-
await this.loadInstance(this.instance.id, true)
265+
await this.loadInstance(this.instance.id)
282266
await this.loadInstanceRetrieval(this.instance.id)
283267

284268
if (!this.unstableClones.size) return
285-
286-
this.updateInstanceTimeoutId = window.setTimeout(
287-
this.liveUpdateInstance,
288-
POLLING_TIME,
289-
)
290269
}
291270

292271
reloadClones = async () => {

0 commit comments

Comments
 (0)