improved tab parent handling

This commit is contained in:
Fabian Freund
2026-01-02 16:53:26 +01:00
parent feb8393a42
commit 3f11325bff
10 changed files with 1951 additions and 32 deletions
@@ -118,14 +118,35 @@ class TabRepository extends _$TabRepository {
selectTabId: selectTabId,
);
// Build sets for validation
final creatingTabIds = createdTabIds.toSet();
final parentIdsToValidate = tabs
.map((tab) => tab.parentId)
.whereType<String>()
.where((id) => !creatingTabIds.contains(id))
.toSet();
// Batch validate parent IDs that aren't in the current creation batch
final existingParentIds =
await tabDao.getExistingTabIds(parentIdsToValidate).get().then((ids) => ids.toSet());
// Upsert all tabs in the database
for (var i = 0; i < createdTabIds.length; i++) {
final tabId = createdTabIds[i];
final tab = tabs[i];
// Validate parent exists in either the batch being created or database
String? validatedParentId;
if (tab.parentId != null) {
if (creatingTabIds.contains(tab.parentId) ||
existingParentIds.contains(tab.parentId)) {
validatedParentId = tab.parentId;
}
}
await tabDao.insertTab(
tabId,
parentId: Value(tab.parentId),
parentId: Value(validatedParentId),
source: TabSource.manual,
containerId: Value(container?.value?.id),
isPrivate: Value(tab.private),
@@ -539,7 +560,7 @@ class TabRepository extends _$TabRepository {
},
);
final tabStateDebouncer = Debouncer(const Duration(seconds: 3));
final tabStateDebouncer = Debouncer(const Duration(seconds: 1));
Map<String, TabState>? debounceStartValue;
ref.listen(
@@ -41,7 +41,7 @@ final class TabRepositoryProvider
}
}
String _$tabRepositoryHash() => r'ea1079570ed2c3424fef6168a7633a10cfb9ac6a';
String _$tabRepositoryHash() => r'6a66c2f1f8d00767d19e6125d4eafc6d93381c8a';
abstract class _$TabRepository extends $Notifier<void> {
void build();