Open Kiranafast2023 opened 1 year ago
db.customStatement('PRAGMA journal_mode=WAL');
This isn't the reason, but WAL
has no effect on the web.
IDB has onlt few entries in a table but each row has 6k of data in which one column consists of ~5k data in JSON text format,
Yes, drift is storing the database in 4k chunks. We're not reading that as JSON though.
What exactly is slow? Writes to the database or reads as well? Reads should be fairly fast because we keep the entire database in memory with IndexedDB. But writes in package:drift/web.dart
are very slow and that is unfixable. You could also the new web implementation which uses a more sound implementation as well.
Thanks for the response, as I can see after adding the new way of implementation code, database transactions are faster now. But on web, when I refresh the page, the database becomes empty. Any idea how to solve this? This was not happening before. This is the code -
DatabaseConnection connectOnWeb() {
return DatabaseConnection.delayed(Future(() async {
final result = await WasmDatabase.open(
databaseName:
'myDb', // prefer to only use valid identifiers here
sqlite3Uri: Uri.parse('sqlite3.wasm'),
driftWorkerUri: Uri.parse('drift_worker.dart.js'),
);
if (result.missingFeatures.isNotEmpty) {
debugPrint('Using ${result.chosenImplementation} due to missing browser '
'features: ${result.missingFeatures}');
}
return result.resolvedExecutor;
}));
}
Interesting, I haven't seen that before. Do you see a message about it using an in-memory implementation due to missing browser features? Or, which implementation is mentioned in the debugPrint
message?
So its not going in the IF condition. I am using latest chrome and if I remove the if condition and try to run debugPrint directly - this is the output it shows Using WasmStorageImplementation.inMemory due to missing browser features: {}
That sounds like something is going very wrong, is there any error before that? Do you have the drift_worker.dart.js
file in web/
? That message can appear when drift was unable to load the worker.
change this line driftWorkerUri: Uri.parse('drift_worker.dart.js'), to driftWorkerUri: Uri.parse('drift_worker.js'),
ensure to add drift_worker.js to web folder
I am using the latest flutter and drift version in my project. When running on web (indexedDb) , it takes a lot of time to fetch the data from databse. IDB has onlt few entries in a table but each row has 6k of data in which one column consists of ~5k data in JSON text format,
This is how I have initialled the DB - final db = Database( WebDatabase.withStorage( DriftWebStorage.indexedDb('worker', migrateFromLocalStorage: false, inWebWorker: true), ), ); db.customStatement('PRAGMA journal_mode=WAL'); Not sure why its so slow on web, on andorid and iOS it works fine