Use method via FFI to compute memories
This commit is contained in:
parent
d4f9a548b6
commit
6f9600690b
4 changed files with 61 additions and 3 deletions
|
@ -15,6 +15,7 @@ import "package:photos/services/filter/db_filters.dart";
|
|||
import 'package:photos/utils/file_uploader_util.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite_migration/sqflite_migration.dart';
|
||||
import 'package:sqlite3/sqlite3.dart' as sqlite3;
|
||||
|
||||
class FilesDB {
|
||||
/*
|
||||
|
@ -100,6 +101,7 @@ class FilesDB {
|
|||
|
||||
// only have a single app-wide reference to the database
|
||||
static Future<Database>? _dbFuture;
|
||||
static Future<sqlite3.Database>? _ffiDBFuture;
|
||||
|
||||
Future<Database> get database async {
|
||||
// lazily instantiate the db the first time it is accessed
|
||||
|
@ -107,6 +109,11 @@ class FilesDB {
|
|||
return _dbFuture!;
|
||||
}
|
||||
|
||||
Future<sqlite3.Database> get ffiDB async {
|
||||
_ffiDBFuture ??= _initFFIDatabase();
|
||||
return _ffiDBFuture!;
|
||||
}
|
||||
|
||||
// this opens the database (and creates it if it doesn't exist)
|
||||
Future<Database> _initDatabase() async {
|
||||
final Directory documentsDirectory =
|
||||
|
@ -116,6 +123,14 @@ class FilesDB {
|
|||
return await openDatabaseWithMigration(path, dbConfig);
|
||||
}
|
||||
|
||||
Future<sqlite3.Database> _initFFIDatabase() async {
|
||||
final Directory documentsDirectory =
|
||||
await getApplicationDocumentsDirectory();
|
||||
final String path = join(documentsDirectory.path, _databaseName);
|
||||
_logger.info("DB path " + path);
|
||||
return sqlite3.sqlite3.open(path);
|
||||
}
|
||||
|
||||
// SQL code to create the database table
|
||||
static List<String> createTable(String tableName) {
|
||||
return [
|
||||
|
@ -749,6 +764,40 @@ class FilesDB {
|
|||
);
|
||||
}
|
||||
|
||||
Future<List<EnteFile>> getFilesCreatedWithinDurationsSync(
|
||||
List<List<int>> durations,
|
||||
Set<int> ignoredCollectionIDs, {
|
||||
int? visibility,
|
||||
String order = 'ASC',
|
||||
}) async {
|
||||
if (durations.isEmpty) {
|
||||
return <EnteFile>[];
|
||||
}
|
||||
final db = await instance.ffiDB;
|
||||
String whereClause = "( ";
|
||||
for (int index = 0; index < durations.length; index++) {
|
||||
whereClause += "($columnCreationTime >= " +
|
||||
durations[index][0].toString() +
|
||||
" AND $columnCreationTime < " +
|
||||
durations[index][1].toString() +
|
||||
")";
|
||||
if (index != durations.length - 1) {
|
||||
whereClause += " OR ";
|
||||
} else if (visibility != null) {
|
||||
whereClause += ' AND $columnMMdVisibility = $visibility';
|
||||
}
|
||||
}
|
||||
whereClause += ")";
|
||||
final results = db.select(
|
||||
'select * from $filesTable where $whereClause order by $columnCreationTime $order',
|
||||
);
|
||||
final files = convertToFiles(results);
|
||||
return applyDBFilters(
|
||||
files,
|
||||
DBFilterOptions(ignoredCollectionIDs: ignoredCollectionIDs),
|
||||
);
|
||||
}
|
||||
|
||||
// Files which user added to a collection manually but they are not
|
||||
// uploaded yet or files belonging to a collection which is marked for backup
|
||||
Future<List<EnteFile>> getFilesPendingForUpload() async {
|
||||
|
|
|
@ -107,7 +107,7 @@ class MemoriesService extends ChangeNotifier {
|
|||
}
|
||||
final ignoredCollections =
|
||||
CollectionsService.instance.archivedOrHiddenCollectionIds();
|
||||
final files = await _filesDB.getFilesCreatedWithinDurations(
|
||||
final files = await _filesDB.getFilesCreatedWithinDurationsSync(
|
||||
durations,
|
||||
ignoredCollections,
|
||||
visibility: visibleVisibility,
|
||||
|
|
12
pubspec.lock
12
pubspec.lock
|
@ -1931,10 +1931,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_common
|
||||
sha256: "8ed044102f3135add97be8653662052838859f5400075ef227f8ad72ae320803"
|
||||
sha256: bb4738f15b23352822f4c42a531677e5c6f522e079461fd240ead29d8d8a54a6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.0+1"
|
||||
version: "2.5.0+2"
|
||||
sqflite_migration:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1943,6 +1943,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
sqlite3:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sqlite3
|
||||
sha256: db65233e6b99e99b2548932f55a987961bc06d82a31a0665451fa0b4fff4c3fb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -140,6 +140,7 @@ dependencies:
|
|||
shared_preferences: ^2.0.5
|
||||
sqflite: ^2.3.0
|
||||
sqflite_migration: ^0.3.0
|
||||
sqlite3: ^2.1.0
|
||||
step_progress_indicator: ^1.0.2
|
||||
styled_text: ^7.0.0
|
||||
syncfusion_flutter_core: ^19.2.49
|
||||
|
|
Loading…
Add table
Reference in a new issue