"In offline mode, executing BriefcaseConnection.openFile is very slow and causes the program to lag." #6592
-
"After packaging an app with Electron, when offline, the first attempt to open a local BIM file using BriefcaseConnection.openFile is extremely slow and leads to program unresponsiveness. This issue does not occur when there is an internet connection." I have used two different iTwin test programs, and both have encountered this issue. This is a screenshot of the code causing the program to become unresponsive: This is the source code: /*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import {
BriefcaseConnection,
IModelConnection,
SnapshotConnection,
} from "@itwin/core-frontend";
import { SampleAppIModelApp } from "../index";
import { Logger, OpenMode } from "@itwin/core-bentley";
import { ElectronApp } from "@itwin/core-electron/lib/cjs/ElectronFrontend";
// cSpell:ignore TESTAPP FILEPATH
export class LocalFileSupport {
public static localFilesSupported = (): boolean => {
if (ElectronApp.isValid) return true;
if (
!SampleAppIModelApp.testAppConfiguration?.snapshotPath &&
!SampleAppIModelApp.testAppConfiguration?.fullSnapshotPath
) {
alert(
"IMJS_UITESTAPP_SNAPSHOT_FILEPATH must be set on the backend and point to a folder containing local snapshot files."
);
return false;
}
return true;
};
public static getLocalFileSpecification = (): string | undefined => {
return SampleAppIModelApp.testAppConfiguration?.fullSnapshotPath;
};
public static openLocalFile = async (
fileSpec: string,
definesFullPath = false
): Promise<IModelConnection | undefined> => {
// Close the current iModelConnection
await SampleAppIModelApp.closeCurrentIModel();
let iModelConnection: IModelConnection | undefined;
let filePath = "";
// Open the iModel
if (ElectronApp.isValid) {
filePath = fileSpec;
Logger.logInfo(
SampleAppIModelApp.loggerCategory(LocalFileSupport),
`openLocalFile: Opening standalone. path=${filePath}`
);
if (document.querySelector(".mask")) {
const eleMask = document.querySelector(".mask");
console.log(eleMask, "eleMask");
(eleMask as any)!.style.display = "block";
}
try {
iModelConnection = await BriefcaseConnection.openStandalone(
filePath,
OpenMode.Readonly,
{ key: filePath }
);
} catch (err: any) {
Logger.logError(
SampleAppIModelApp.loggerCategory(LocalFileSupport),
`openLocalFile: BriefcaseConnection.openStandalone failed.`
);
alert(err.message);
iModelConnection = undefined;
}
} else {
if (
SampleAppIModelApp.testAppConfiguration?.fullSnapshotPath &&
definesFullPath
)
filePath = fileSpec;
else
filePath = `${SampleAppIModelApp.testAppConfiguration?.snapshotPath}/${fileSpec}`;
Logger.logInfo(
SampleAppIModelApp.loggerCategory(LocalFileSupport),
`openLocalFile: Opening snapshot. path=${filePath}`
);
try {
iModelConnection = await SnapshotConnection.openFile(filePath);
} catch (err: any) {
alert(err.message);
iModelConnection = undefined;
}
}
return iModelConnection;
};
} "I want to avoid encountering this issue when offline. I would greatly appreciate any helpful solutions you may have. Looking forward to your response." |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 11 replies
-
Check for attempted network requests. Check browser console for errors. |
Beta Was this translation helpful? Give feedback.
-
Can you generate a CPU profile of your program to share, so you can confirm which function is taking so long and how long? |
Beta Was this translation helpful? Give feedback.
-
I now see that I added a syncOnConnect option to opening workspaces that defaults to true. That's so we always check to see if there is a new version available. That's what's causing the attempt to load the manifest. Can you try adding in backend.setting.json5: "workspace/databases": [
{
"name": "gcs/base",
"dbName": "base",
"containerName": "gcs/container",
"version": "^1",
"priority": 10000,
"prefetch": true,
**"syncOnConnect": false**
},
{
"name": "gcs/entire-earth",
"dbName": "allEarth",
"containerName": "gcs/container",
"version": "^1",
"priority": 100,
**"syncOnConnect": false**
}, and see if it works? We'll have to give some way to tell when we're offline so we can avoid things like this. |
Beta Was this translation helpful? Give feedback.
-
Adding syncOnConnect:false to backend.setting.json5 does not help to get rid of Here's the log with Internet Logs with InternetInfo | CloudSqlite | 11:54:45.917 | invoking xAuth(azure?customuri=1&sas=1, https://geocoord-workspace.itwinjs.org, gcs) Info | CloudSqlite | 11:54:45.921 | r0 [] GET https://geocoord-workspace.itwinjs.org/gcs/manifest.bcv?... \ Info | CloudSqlite | 11:54:46.211 | r0 [] [290ms] (http=200) (rc=0) HTTP/1.1 200 OK Trace | CloudSqlite | 11:54:50.299 | poll Info | CloudSqlite | 11:54:50.299 | container gcs enters POLL state Info | CloudSqlite | 11:54:50.300 | r1 [] GET https://geocoord-workspace.itwinjs.org/gcs/manifest.bcv?... Info | CloudSqlite | 11:54:50.363 | r1 [] [63ms] (http=200) (rc=0) HTTP/1.1 200 OK Info | CloudSqlite | 11:54:50.364 | container gcs leaves POLL state According to the logs, there are two http calls to fetch the manifest file, the first call happens at Further dive into We came up with several options
Any thoughts on the above options? |
Beta Was this translation helpful? Give feedback.
-
can you please provide a calltrace of how we get to fecthManifest? |
Beta Was this translation helpful? Give feedback.
-
Sure. Here's a calltrace to fetchManifest while connecting a cloud container to local cache
|
Beta Was this translation helpful? Give feedback.
-
@jh9636 We had a group discussion about it, this issue arises from
|
Beta Was this translation helpful? Give feedback.
@jh9636 We had a group discussion about it, this issue arises from
cloudContainer.checkForChanges();
To get rid of it, we have the following suggestion:itwin/core-backend
in your node_modules and find/lib/cjs/assets/Settings
folder, if you use pnpm then the path may look something like\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]\node_modules\@itwin\core-backend\lib\cjs\assets\Settings\backend.setting.json5
backend.setting.json5
, add"syncOnConnect": false
tocloud/containers
"