This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,079 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import "dart:io"; | ||
|
||
import "package:isar/isar.dart"; | ||
import 'package:path_provider/path_provider.dart'; | ||
import "package:photos/core/event_bus.dart"; | ||
import "package:photos/events/embedding_updated_event.dart"; | ||
import "package:photos/models/embedding.dart"; | ||
|
||
class EmbeddingsDB { | ||
late final Isar _isar; | ||
|
||
EmbeddingsDB._privateConstructor(); | ||
|
||
static final EmbeddingsDB instance = EmbeddingsDB._privateConstructor(); | ||
|
||
Future<void> init() async { | ||
final dir = await getApplicationDocumentsDirectory(); | ||
_isar = await Isar.open( | ||
[EmbeddingSchema], | ||
directory: dir.path, | ||
); | ||
await _clearDeprecatedStore(dir); | ||
} | ||
|
||
Future<void> clearTable() async { | ||
await _isar.clear(); | ||
} | ||
|
||
Future<List<Embedding>> getAll(Model model) async { | ||
return _isar.embeddings.filter().modelEqualTo(model).findAll(); | ||
} | ||
|
||
Future<void> put(Embedding embedding) { | ||
return _isar.writeTxn(() async { | ||
await _isar.embeddings.put(embedding); | ||
Bus.instance.fire(EmbeddingUpdatedEvent()); | ||
}); | ||
} | ||
|
||
Future<void> putMany(List<Embedding> embeddings) { | ||
return _isar.writeTxn(() async { | ||
await _isar.embeddings.putAll(embeddings); | ||
Bus.instance.fire(EmbeddingUpdatedEvent()); | ||
}); | ||
} | ||
|
||
Future<List<Embedding>> getUnsyncedEmbeddings() async { | ||
return await _isar.embeddings.filter().updationTimeEqualTo(null).findAll(); | ||
} | ||
|
||
Future<void> deleteAllForModel(Model model) async { | ||
await _isar.writeTxn(() async { | ||
final embeddings = | ||
await _isar.embeddings.filter().modelEqualTo(model).findAll(); | ||
await _isar.embeddings.deleteAll(embeddings.map((e) => e.id).toList()); | ||
Bus.instance.fire(EmbeddingUpdatedEvent()); | ||
}); | ||
} | ||
|
||
Future<void> _clearDeprecatedStore(Directory dir) async { | ||
final deprecatedStore = Directory(dir.path + "/object-box-store"); | ||
if (await deprecatedStore.exists()) { | ||
await deprecatedStore.delete(recursive: true); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.