Skip to content

Commit 83dd009

Browse files
feat(cat-voices): database optimization (#3655)
* feat(cat-voices): database migration (#3585) * docs: capture initial times * chore: remove cacheDocument * turn off logging * chore: use debugPrint instead of logger * feat: bulk documents save * batching sync * chore: move exact ref resoling to getDocumentData instead of index * fix: DocumentRepository * chore: simplify getting documents data * remove getAllDocumentsRefs and getCachedDocumentsRefs from DocumentRepository. Index is only available in DocumentDataRemoteSource * chore: update docs * simplified document index endpoint * remove randomness from LocalCatGateway * indexing by batch size * wip: filtering by types * Rework filtering refs + checking all refs if already cached in parallel * docs * update indexing.csv * update indexing csv * chore: cleanup * trailing new line * chore * move performance tab to docs * bulk saving typed docs in parallel * chore: revert hardcoded timestamp * chore: typos * split _sync into smaller functions + add documentation * little refactor * fix: analyzer * initial v2 tables * wip * wip * feat: database migration * chore: cleanup * bump batch size * cleanup * chore: remove defensive content decoding * spelling * test on platform * chore: update build scripts * more migration test data * clean up constructors * cleanup * fix: template tests * fix: spelling * fix code-generator earthly target * use logger in migration + wrap in transaction * chore: move migration transaction level higher * feat(cat-voices): database queries migration and optimization (#3614) * docs: capture initial times * chore: remove cacheDocument * turn off logging * chore: use debugPrint instead of logger * feat: bulk documents save * batching sync * chore: move exact ref resoling to getDocumentData instead of index * fix: DocumentRepository * chore: simplify getting documents data * remove getAllDocumentsRefs and getCachedDocumentsRefs from DocumentRepository. Index is only available in DocumentDataRemoteSource * chore: update docs * simplified document index endpoint * remove randomness from LocalCatGateway * indexing by batch size * wip: filtering by types * Rework filtering refs + checking all refs if already cached in parallel * docs * update indexing.csv * update indexing csv * chore: cleanup * trailing new line * chore * move performance tab to docs * bulk saving typed docs in parallel * chore: revert hardcoded timestamp * chore: typos * split _sync into smaller functions + add documentation * little refactor * fix: analyzer * initial v2 tables * wip * wip * feat: database migration * chore: cleanup * bump batch size * cleanup * chore: remove defensive content decoding * chore: daos * spelling * saveAll * test on platform * chore: update build scripts * feat: DocumentsV2Dao methods * simple proposals pagination query * chore: create a JoinedProposalBriefEntity * rename method * feat: exclude hidden proposals * more tests * renaming and splitting logic into smaller parts * feat: per language strategy * remove CatalystDatabaseLanguage in favor of raw queries as they are easier to mange * remove Index Strategy Documentation * handle case where ref is empty * migration now includes indexes * use v2 documents table for saveAll and isCachedBulk * adds ActionType to JoinedProposalBriefEntity * adds versionIds to JoinedProposalBriefEntity * comments count * adds isFavorite to JoinedProposalBriefEntity * add template to JoinedProposalBriefEntity * adds documentsLocalMetadata table for auto updates * Update docs * use v2 proposals query for discovery most recent section * feat: simplify most recent proposals section * add proposal fav status for v2 tables * local proposal fav status update * update fav state locally for faster feedback * self review * fix tests * update times * fix: analyzer * more migration test data * clean up constructors * cleanup * fix: template tests * spelling * fix: spelling * chore: PR review adjustments * fix: add discovery specific colors (#3637) * fix code-generator earthly target * use logger in migration + wrap in transaction --------- Co-authored-by: Ryszard Schossler <[email protected]> * feat(cat-voices): proposals query filtering (#3641) * docs: capture initial times * chore: remove cacheDocument * turn off logging * chore: use debugPrint instead of logger * feat: bulk documents save * batching sync * chore: move exact ref resoling to getDocumentData instead of index * fix: DocumentRepository * chore: simplify getting documents data * remove getAllDocumentsRefs and getCachedDocumentsRefs from DocumentRepository. Index is only available in DocumentDataRemoteSource * chore: update docs * simplified document index endpoint * remove randomness from LocalCatGateway * indexing by batch size * wip: filtering by types * Rework filtering refs + checking all refs if already cached in parallel * docs * update indexing.csv * update indexing csv * chore: cleanup * trailing new line * chore * move performance tab to docs * bulk saving typed docs in parallel * chore: revert hardcoded timestamp * chore: typos * split _sync into smaller functions + add documentation * little refactor * fix: analyzer * initial v2 tables * wip * wip * feat: database migration * chore: cleanup * bump batch size * cleanup * chore: remove defensive content decoding * chore: daos * spelling * saveAll * test on platform * chore: update build scripts * feat: DocumentsV2Dao methods * simple proposals pagination query * chore: create a JoinedProposalBriefEntity * rename method * feat: exclude hidden proposals * more tests * renaming and splitting logic into smaller parts * feat: per language strategy * remove CatalystDatabaseLanguage in favor of raw queries as they are easier to mange * remove Index Strategy Documentation * handle case where ref is empty * migration now includes indexes * use v2 documents table for saveAll and isCachedBulk * adds ActionType to JoinedProposalBriefEntity * adds versionIds to JoinedProposalBriefEntity * comments count * adds isFavorite to JoinedProposalBriefEntity * add template to JoinedProposalBriefEntity * adds documentsLocalMetadata table for auto updates * Update docs * use v2 proposals query for discovery most recent section * feat: simplify most recent proposals section * add proposal fav status for v2 tables * local proposal fav status update * update fav state locally for faster feedback * self review * fix tests * update times * fix: analyzer * more migration test data * clean up constructors * cleanup * fix: template tests * spelling * fix: spelling * chore: PR review adjustments * add order parameter * ProposalsOrder docs * GetProposalsBriefPage supports order * add filters object * proposalsBriefPage filtering * fix: status filtering * more draft proposals filtering tests * Campaign proposals filter * update docs * expose getVisibleProposalsCount and tests * expose filters parameter * integrate proposals page with v2 queries * chore: increase time diff between proposals * chore: reduce count query tables watched when not needed * local proposals cubit * local proposal fav staus update * docs * fix: add discovery specific colors (#3637) * fix code-generator earthly target * use logger in migration + wrap in transaction * spelling * rename category to categoryId for better consistency * proposals per tab selector * release completed in close * extract early return logic into function --------- Co-authored-by: Ryszard Schossler <[email protected]> * feat(cat-voices): voting space (#3648) * docs: capture initial times * chore: remove cacheDocument * turn off logging * chore: use debugPrint instead of logger * feat: bulk documents save * batching sync * chore: move exact ref resoling to getDocumentData instead of index * fix: DocumentRepository * chore: simplify getting documents data * remove getAllDocumentsRefs and getCachedDocumentsRefs from DocumentRepository. Index is only available in DocumentDataRemoteSource * chore: update docs * simplified document index endpoint * remove randomness from LocalCatGateway * indexing by batch size * wip: filtering by types * Rework filtering refs + checking all refs if already cached in parallel * docs * update indexing.csv * update indexing csv * chore: cleanup * trailing new line * chore * move performance tab to docs * bulk saving typed docs in parallel * chore: revert hardcoded timestamp * chore: typos * split _sync into smaller functions + add documentation * little refactor * fix: analyzer * initial v2 tables * wip * wip * feat: database migration * chore: cleanup * bump batch size * cleanup * chore: remove defensive content decoding * chore: daos * spelling * saveAll * test on platform * chore: update build scripts * feat: DocumentsV2Dao methods * simple proposals pagination query * chore: create a JoinedProposalBriefEntity * rename method * feat: exclude hidden proposals * more tests * renaming and splitting logic into smaller parts * feat: per language strategy * remove CatalystDatabaseLanguage in favor of raw queries as they are easier to mange * remove Index Strategy Documentation * handle case where ref is empty * migration now includes indexes * use v2 documents table for saveAll and isCachedBulk * adds ActionType to JoinedProposalBriefEntity * adds versionIds to JoinedProposalBriefEntity * comments count * adds isFavorite to JoinedProposalBriefEntity * add template to JoinedProposalBriefEntity * adds documentsLocalMetadata table for auto updates * Update docs * use v2 proposals query for discovery most recent section * feat: simplify most recent proposals section * add proposal fav status for v2 tables * local proposal fav status update * update fav state locally for faster feedback * self review * fix tests * update times * fix: analyzer * more migration test data * clean up constructors * cleanup * fix: template tests * spelling * fix: spelling * chore: PR review adjustments * add order parameter * ProposalsOrder docs * GetProposalsBriefPage supports order * add filters object * proposalsBriefPage filtering * fix: status filtering * more draft proposals filtering tests * Campaign proposals filter * update docs * expose getVisibleProposalsCount and tests * expose filters parameter * integrate proposals page with v2 queries * chore: increase time diff between proposals * chore: reduce count query tables watched when not needed * local proposals cubit * local proposal fav staus update * docs * fix: add discovery specific colors (#3637) * fix code-generator earthly target * use logger in migration + wrap in transaction * spelling * wip * rename category to categoryId for better consistency * adding vote data to ProposalBriefData * fix: dependencies * voting page + cubit integration - wip * proposals per tab selector * release completed in close * extract early return logic into function * Voting tabs selector + releasing completer on close * move spaces blocs to shell page level * fix: voting in grid view * dummy voting integration * chore: remove showComments * docs: ProposalOrDocument --------- Co-authored-by: Ryszard Schossler <[email protected]> * feat(cat-voices): database queries cleanup (#3672) * docs: capture initial times * chore: remove cacheDocument * turn off logging * chore: use debugPrint instead of logger * feat: bulk documents save * batching sync * chore: move exact ref resoling to getDocumentData instead of index * fix: DocumentRepository * chore: simplify getting documents data * remove getAllDocumentsRefs and getCachedDocumentsRefs from DocumentRepository. Index is only available in DocumentDataRemoteSource * chore: update docs * simplified document index endpoint * remove randomness from LocalCatGateway * indexing by batch size * wip: filtering by types * Rework filtering refs + checking all refs if already cached in parallel * docs * update indexing.csv * update indexing csv * chore: cleanup * trailing new line * chore * move performance tab to docs * bulk saving typed docs in parallel * chore: revert hardcoded timestamp * chore: typos * split _sync into smaller functions + add documentation * little refactor * fix: analyzer * initial v2 tables * wip * wip * feat: database migration * chore: cleanup * bump batch size * cleanup * chore: remove defensive content decoding * chore: daos * spelling * saveAll * test on platform * chore: update build scripts * feat: DocumentsV2Dao methods * simple proposals pagination query * chore: create a JoinedProposalBriefEntity * rename method * feat: exclude hidden proposals * more tests * renaming and splitting logic into smaller parts * feat: per language strategy * remove CatalystDatabaseLanguage in favor of raw queries as they are easier to mange * remove Index Strategy Documentation * handle case where ref is empty * migration now includes indexes * use v2 documents table for saveAll and isCachedBulk * adds ActionType to JoinedProposalBriefEntity * adds versionIds to JoinedProposalBriefEntity * comments count * adds isFavorite to JoinedProposalBriefEntity * add template to JoinedProposalBriefEntity * adds documentsLocalMetadata table for auto updates * Update docs * use v2 proposals query for discovery most recent section * feat: simplify most recent proposals section * add proposal fav status for v2 tables * local proposal fav status update * update fav state locally for faster feedback * self review * fix tests * update times * fix: analyzer * more migration test data * clean up constructors * cleanup * fix: template tests * spelling * fix: spelling * chore: PR review adjustments * add order parameter * ProposalsOrder docs * GetProposalsBriefPage supports order * add filters object * proposalsBriefPage filtering * fix: status filtering * more draft proposals filtering tests * Campaign proposals filter * update docs * expose getVisibleProposalsCount and tests * expose filters parameter * integrate proposals page with v2 queries * chore: increase time diff between proposals * chore: reduce count query tables watched when not needed * local proposals cubit * local proposal fav staus update * docs * fix: add discovery specific colors (#3637) * fix code-generator earthly target * use logger in migration + wrap in transaction * spelling * wip * rename category to categoryId for better consistency * adding vote data to ProposalBriefData * fix: dependencies * voting page + cubit integration - wip * proposals per tab selector * release completed in close * extract early return logic into function * Voting tabs selector + releasing completer on close * move spaces blocs to shell page level * fix: voting in grid view * dummy voting integration * chore: remove showComments * docs: ProposalOrDocument * create proposals/count query .csv files * update proposals query times * category indexes * CatId parse and tryParse * create new tables for authors * update migration * run database analyze after sync * DocumentAuthors docs * simpler copyWith * cat.id keeps schema * get rid of authorCatIdWithoutUsername column * console profiler * catId -> id * times * results notes * spelling * fix: analyzer * update results (#3673) * fix: readme * remove CatalystRuntimeProfiler * catId schema -> scheme * rename * bring back profiler to SignedDocumentManager, with debounce --------- Co-authored-by: Ryszard Schossler <[email protected]> * feat(cat-voices): campaign total ask (#3734) * remove totalAsk and proposalsCount from campaign model * proposalsCount -> finalProposalsCount * CampaignCategoryViewModel.id -> CampaignCategoryViewModel.ref * little DiscoveryCubit state build cleanup * watch campaign total ask in discovery * smaller voting category model * new proposal campaign * safe check * proposal builder category total ask * chore: missing TODO * category details * watch proposals template total ask * finish integration of total_ask * close * remove print and add TODO * documents getLatestOf * categoryId -> categoryRef * chore: make logger private * feat: Make MultiCurrencyAmount immutable * chore(cat-voices): remove old daos (#3745) * remove totalAsk and proposalsCount from campaign model * proposalsCount -> finalProposalsCount * CampaignCategoryViewModel.id -> CampaignCategoryViewModel.ref * little DiscoveryCubit state build cleanup * watch campaign total ask in discovery * smaller voting category model * new proposal campaign * safe check * proposal builder category total ask * chore: missing TODO * category details * watch proposals template total ask * finish integration of total_ask * close * remove print and add TODO * documents getLatestOf * remove old tables and daos * deleteWhere tests * remove old pagination and count methods * local draft documents dao * categoryId -> categoryRef * chore: notInType -> typeNotIn * chore: move DriftDocumentsV2LocalMetadataDao setup into group * separate get and getWhere * docs: documents sources interfaces documentation * chore: methods rename * chore: refTo -> referencing * chore: typeNotIn -> excludeTypes * update content * feat(cat-voices): smaller proposals query scope (#3747) * smaller proposals page query * update PR nr * test(cat-voices): enable back index tests (#3766) * chore: remote source tests * SyncManager and DocumentService tests * chore(cat-voices): cleanup miss leading "ref" / "selfRef" with "id" (#3762) * remove totalAsk and proposalsCount from campaign model * proposalsCount -> finalProposalsCount * CampaignCategoryViewModel.id -> CampaignCategoryViewModel.ref * little DiscoveryCubit state build cleanup * watch campaign total ask in discovery * smaller voting category model * new proposal campaign * safe check * proposal builder category total ask * chore: missing TODO * category details * watch proposals template total ask * finish integration of total_ask * close * remove print and add TODO * documents getLatestOf * remove old tables and daos * deleteWhere tests * remove old pagination and count methods * local draft documents dao * categoryId -> categoryRef * chore: notInType -> typeNotIn * chore: move DriftDocumentsV2LocalMetadataDao setup into group * separate get and getWhere * docs: documents sources interfaces documentation * chore: methods rename * chore: refTo -> referencing * chore: typeNotIn -> excludeTypes * update content * feat(cat-voices): smaller proposals query scope (#3747) * smaller proposals page query * update PR nr * silence warning * chore: version -> ver * fix: ref test * chore: remove id and version getters from DocumentDataMetadata * selfRef -> id part1 * chore: selfRef -> id * chore: use more of ids * chore: use Map.of instead of Map.from * dtos migration tests * fix: analyzer --------- Co-authored-by: Ryszard Schossler <[email protected]>
1 parent 1960515 commit 83dd009

File tree

257 files changed

+18552
-9811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+18552
-9811
lines changed

.config/dictionaries/project.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ Utxos
399399
uuidv
400400
varint
401401
Vespr
402+
vers
402403
vite
403404
vitss
404405
vkey

catalyst_voices/Earthfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ code-generator:
3232

3333
LET gen_code_path = lib/generated/api
3434
LET local_gen_code_path = packages/internal/catalyst_voices_repositories/lib/generated/api/
35+
LET local_gen_db_code_path = packages/internal/catalyst_voices_repositories/test/src/database/migration/catalyst_database/generated/
3536

3637
WORKDIR packages/internal/catalyst_voices_repositories
3738

3839
WORKDIR /frontend
3940

4041
RUN melos l10n
42+
RUN melos build-db-migration
4143
RUN melos build-runner
4244
RUN melos build-runner-repository
4345

@@ -58,6 +60,11 @@ code-generator:
5860
-o -name "*.drift.dart" \))
5961
SAVE ARTIFACT $generated_file AS LOCAL $generated_file
6062
END
63+
64+
# Save database migration generated files
65+
WORKDIR packages/internal/catalyst_voices_repositories/test/src/database/migration/catalyst_database
66+
SAVE ARTIFACT generated/* AS LOCAL $local_gen_db_code_path
67+
WORKDIR /frontend
6168
ELSE
6269
SAVE ARTIFACT .
6370
END

catalyst_voices/apps/voices/lib/app/view/app.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,9 @@ class _AppState extends State<App> {
4747
BlocProvider<SessionCubit>(
4848
create: (_) => Dependencies.instance.get<SessionCubit>(),
4949
),
50-
BlocProvider<ProposalsCubit>(
51-
create: (_) => Dependencies.instance.get<ProposalsCubit>(),
52-
),
53-
BlocProvider<VotingCubit>(
54-
create: (_) => Dependencies.instance.get<VotingCubit>(),
55-
),
5650
BlocProvider<CampaignBuilderCubit>(
5751
create: (_) => Dependencies.instance.get<CampaignBuilderCubit>(),
5852
),
59-
BlocProvider<WorkspaceBloc>(
60-
create: (context) => Dependencies.instance.get<WorkspaceBloc>(),
61-
),
62-
BlocProvider<DiscoveryCubit>(
63-
create: (context) => Dependencies.instance.get<DiscoveryCubit>(),
64-
),
6553
BlocProvider<CategoryDetailCubit>(
6654
create: (_) => Dependencies.instance.get<CategoryDetailCubit>(),
6755
),

catalyst_voices/apps/voices/lib/configs/bootstrap.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,13 @@ Future<BootstrapArgs> bootstrap({
9191
fromTo: DateRange(from: startConfigTimestamp, to: endConfigTimestamp),
9292
);
9393

94-
final runtimeProfiler = CatalystRuntimeProfiler(profiler)..start(at: bootstrapStartTimestamp);
95-
9694
await Dependencies.instance.init(
9795
config: config,
9896
environment: environment,
9997
loggingService: _loggingService,
10098
reportingService: _reportingService,
10199
profiler: profiler,
102100
startupProfiler: startupProfiler,
103-
runtimeProfiler: runtimeProfiler,
104101
);
105102

106103
final router = buildAppRouter(initialLocation: initialLocation);
@@ -185,8 +182,8 @@ Future<void> cleanUpStorages({
185182
Future<void> cleanUpUserDataFromDatabase() async {
186183
final db = Dependencies.instance.get<CatalystDatabase>();
187184

188-
await db.draftsDao.deleteWhere();
189-
await db.favoritesDao.deleteAll();
185+
await db.localDocumentsV2Dao.deleteWhere();
186+
await db.localMetadataDao.deleteWhere();
190187
}
191188

192189
@visibleForTesting
@@ -216,14 +213,16 @@ Future<void> registerDependencies({
216213
/// - [CatalystNoopProfiler] for debug mode (no overhead)
217214
CatalystProfiler _createProfiler(AppConfig config) {
218215
if (kProfileMode) {
219-
return CatalystDeveloperProfiler.fromConfig(config.developerProfiler);
216+
return config.profiler.console
217+
? const CatalystProfiler.console()
218+
: CatalystProfiler.developer(config.profiler);
220219
}
221220

222221
if (_shouldUseSentry) {
223-
return const CatalystSentryProfiler();
222+
return const CatalystProfiler.sentry();
224223
}
225224

226-
return const CatalystNoopProfiler();
225+
return const CatalystProfiler.noop();
227226
}
228227

229228
void _debugPrintStressTest() {

catalyst_voices/apps/voices/lib/dependency/dependencies.dart

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ final class Dependencies extends DependencyProvider {
4242
required ReportingService reportingService,
4343
CatalystProfiler? profiler,
4444
CatalystStartupProfiler? startupProfiler,
45-
CatalystRuntimeProfiler? runtimeProfiler,
4645
}) async {
4746
DependencyProvider.instance = this;
4847

@@ -56,9 +55,6 @@ final class Dependencies extends DependencyProvider {
5655
if (startupProfiler != null) {
5756
registerSingleton(startupProfiler);
5857
}
59-
if (runtimeProfiler != null) {
60-
registerSingleton(runtimeProfiler);
61-
}
6258

6359
_registerStorages();
6460
_registerUtils();
@@ -113,20 +109,18 @@ final class Dependencies extends DependencyProvider {
113109
blockchainConfig: get<AppConfig>().blockchain,
114110
);
115111
})
116-
..registerLazySingleton<ProposalsCubit>(
112+
..registerFactory<ProposalsCubit>(
117113
() => ProposalsCubit(
118114
get<UserService>(),
119115
get<CampaignService>(),
120116
get<ProposalService>(),
121117
),
122118
)
123-
..registerLazySingleton<VotingCubit>(
119+
..registerFactory<VotingCubit>(
124120
() => VotingCubit(
125121
get<UserService>(),
126122
get<CampaignService>(),
127123
get<ProposalService>(),
128-
get<VotingBallotBuilder>(),
129-
get<VotingService>(),
130124
),
131125
)
132126
// TODO(LynxLynxx): add repository for campaign management
@@ -171,6 +165,7 @@ final class Dependencies extends DependencyProvider {
171165
get<ProposalService>(),
172166
get<CommentService>(),
173167
get<CampaignService>(),
168+
get<DocumentsService>(),
174169
get<DocumentMapper>(),
175170
get<VotingBallotBuilder>(),
176171
get<VotingService>(),
@@ -249,10 +244,11 @@ final class Dependencies extends DependencyProvider {
249244
return BlockchainRepository(get<ApiServices>());
250245
})
251246
..registerLazySingleton<SignedDocumentManager>(() {
247+
final profiler = get<CatalystProfiler>();
252248
return SignedDocumentManager(
253249
brotli: const CatalystBrotliCompressor(),
254250
zstd: const CatalystZstdCompressor(),
255-
profiler: get<CatalystRuntimeProfiler>(),
251+
profiler: profiler is CatalystConsoleProfiler ? profiler : const CatalystNoopProfiler(),
256252
);
257253
})
258254
..registerLazySingleton<DatabaseDraftsDataSource>(() {
@@ -263,11 +259,7 @@ final class Dependencies extends DependencyProvider {
263259
..registerLazySingleton<DatabaseDocumentsDataSource>(() {
264260
return DatabaseDocumentsDataSource(
265261
get<CatalystDatabase>(),
266-
);
267-
})
268-
..registerLazySingleton<DocumentFavoriteSource>(() {
269-
return DatabaseDocumentFavoriteSource(
270-
get<CatalystDatabase>(),
262+
get<CatalystProfiler>(),
271263
);
272264
})
273265
..registerLazySingleton<CatGatewayDocumentDataSource>(() {
@@ -276,13 +268,19 @@ final class Dependencies extends DependencyProvider {
276268
get<SignedDocumentManager>(),
277269
);
278270
})
279-
..registerLazySingleton<CampaignRepository>(CampaignRepository.new)
271+
..registerLazySingleton<CampaignRepository>(
272+
() {
273+
return CampaignRepository(
274+
get<DatabaseDocumentsDataSource>(),
275+
);
276+
},
277+
)
280278
..registerLazySingleton<DocumentRepository>(() {
281279
return DocumentRepository(
280+
get<CatalystDatabase>(),
282281
get<DatabaseDraftsDataSource>(),
283282
get<DatabaseDocumentsDataSource>(),
284283
get<CatGatewayDocumentDataSource>(),
285-
get<DocumentFavoriteSource>(),
286284
);
287285
})
288286
..registerLazySingleton<DocumentMapper>(() => const DocumentMapperImpl())
@@ -400,6 +398,7 @@ final class Dependencies extends DependencyProvider {
400398
get<SignerService>(),
401399
get<ActiveCampaignObserver>(),
402400
get<CastedVotesObserver>(),
401+
get<VotingBallotBuilder>(),
403402
);
404403
});
405404
registerLazySingleton<CommentService>(() {
@@ -520,6 +519,7 @@ final class Dependencies extends DependencyProvider {
520519
get<SyncStatsStorage>(),
521520
get<DocumentsService>(),
522521
get<CampaignService>(),
522+
get<CatalystProfiler>(),
523523
);
524524
},
525525
dispose: (manager) async => manager.dispose(),
@@ -542,7 +542,10 @@ final class Dependencies extends DependencyProvider {
542542
dispose: (observer) async => observer.dispose(),
543543
);
544544
registerLazySingleton<CastedVotesObserver>(CastedVotesObserverImpl.new);
545-
registerLazySingleton<VotingBallotBuilder>(VotingBallotLocalBuilder.new);
545+
registerLazySingleton<VotingBallotBuilder>(
546+
VotingBallotLocalBuilder.new,
547+
dispose: (builder) => builder.dispose(),
548+
);
546549

547550
// Not a singleton
548551
registerFactory<RegistrationStatusPoller>(

catalyst_voices/apps/voices/lib/pages/category/card_information.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class CardInformation extends StatelessWidget {
2828
padding: padding,
2929
children: [
3030
CategoryProposalsDetailsCard(
31-
categoryId: category.id,
31+
categoryRef: category.ref,
3232
categoryName: category.formattedName,
33-
categoryProposalsCount: category.proposalsCount,
33+
categoryFinalProposalsCount: category.finalProposalsCount,
3434
),
3535
const SizedBox(height: 16),
3636
Offstage(
3737
offstage: !isActiveProposer,
3838
child: CreateProposalCard(
39-
categoryId: category.id,
39+
categoryRef: category.ref,
4040
categoryName: category.formattedName,
4141
categoryDos: category.dos,
4242
categoryDonts: category.donts,

catalyst_voices/apps/voices/lib/pages/category/category_compact_detail_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CategoryCompactDetailView extends StatelessWidget {
3232
_CategoryBrief(
3333
categoryName: category.formattedName,
3434
categoryDescription: category.description,
35-
categoryRef: category.id,
35+
categoryRef: category.ref,
3636
),
3737
FundsDetailCard(
3838
allFunds: category.availableFunds,

catalyst_voices/apps/voices/lib/pages/category/category_detail_view.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class CategoryDetailView extends StatelessWidget {
3232
_CategoryBrief(
3333
categoryName: category.formattedName,
3434
categoryDescription: category.description,
35-
categoryRef: category.id,
35+
categoryRef: category.ref,
3636
image: category.image,
37-
proposalCount: category.proposalsCount,
37+
finalProposalsCount: category.finalProposalsCount,
3838
),
3939
const SizedBox(height: 64),
4040
FundsDetailCard(
@@ -59,14 +59,14 @@ class _CategoryBrief extends StatelessWidget {
5959
final String categoryDescription;
6060
final SignedDocumentRef categoryRef;
6161
final SvgGenImage image;
62-
final int proposalCount;
62+
final int finalProposalsCount;
6363

6464
const _CategoryBrief({
6565
required this.categoryName,
6666
required this.categoryDescription,
6767
required this.categoryRef,
6868
required this.image,
69-
required this.proposalCount,
69+
required this.finalProposalsCount,
7070
});
7171

7272
@override
@@ -98,7 +98,7 @@ class _CategoryBrief extends StatelessWidget {
9898
categoryName: categoryName,
9999
categoryDescription: categoryDescription,
100100
categoryRef: categoryRef,
101-
showViewAllButton: proposalCount > 0,
101+
showViewAllButton: finalProposalsCount > 0,
102102
),
103103
),
104104
],

catalyst_voices/apps/voices/lib/pages/category/category_page.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import 'package:flutter/material.dart';
1616
import 'package:skeletonizer/skeletonizer.dart';
1717

1818
class CategoryPage extends StatefulWidget {
19-
final SignedDocumentRef categoryId;
19+
final SignedDocumentRef categoryRef;
2020

21-
const CategoryPage({super.key, required this.categoryId});
21+
const CategoryPage({super.key, required this.categoryRef});
2222

2323
@override
2424
State<CategoryPage> createState() => _CategoryPageState();
@@ -106,6 +106,8 @@ class _CategoryDetailContent extends StatelessWidget {
106106

107107
@override
108108
Widget build(BuildContext context) {
109+
// TODO(damian-molinski): refactor it into single class object in category_detail_state.dart
110+
// and do not rely on context.select<SessionCubit> here.
109111
return BlocSelector<
110112
CategoryDetailCubit,
111113
CategoryDetailState,
@@ -114,7 +116,7 @@ class _CategoryDetailContent extends StatelessWidget {
114116
selector: (state) {
115117
return (
116118
show: state.isLoading,
117-
data: state.category ?? CampaignCategoryDetailsViewModel.placeholder(),
119+
data: state.selectedCategoryDetails ?? CampaignCategoryDetailsViewModel.placeholder(),
118120
);
119121
},
120122
builder: (context, state) {
@@ -139,9 +141,9 @@ class _CategoryDetailContent extends StatelessWidget {
139141
}
140142

141143
class _CategoryDetailError extends StatelessWidget {
142-
final SignedDocumentRef categoryId;
144+
final SignedDocumentRef categoryRef;
143145

144-
const _CategoryDetailError({required this.categoryId});
146+
const _CategoryDetailError({required this.categoryRef});
145147

146148
@override
147149
Widget build(BuildContext context) {
@@ -165,7 +167,7 @@ class _CategoryDetailError extends StatelessWidget {
165167
? null
166168
: () {
167169
unawaited(
168-
context.read<CategoryDetailCubit>().getCategoryDetail(categoryId),
170+
context.read<CategoryDetailCubit>().getCategoryDetail(categoryRef),
169171
);
170172
},
171173
),
@@ -187,7 +189,7 @@ class _CategoryPageState extends State<CategoryPage> {
187189
children: [
188190
const _CategoryDetailContent(),
189191
_CategoryDetailError(
190-
categoryId: widget.categoryId,
192+
categoryRef: widget.categoryRef,
191193
),
192194
].constrainedDelegate(),
193195
),
@@ -198,9 +200,9 @@ class _CategoryPageState extends State<CategoryPage> {
198200
void didUpdateWidget(CategoryPage oldWidget) {
199201
super.didUpdateWidget(oldWidget);
200202

201-
if (widget.categoryId != oldWidget.categoryId) {
203+
if (widget.categoryRef != oldWidget.categoryRef) {
202204
unawaited(
203-
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryId),
205+
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryRef),
204206
);
205207
}
206208
}
@@ -215,17 +217,16 @@ class _CategoryPageState extends State<CategoryPage> {
215217
@override
216218
void initState() {
217219
super.initState();
218-
unawaited(context.read<CategoryDetailCubit>().getCategories());
219-
unawaited(
220-
context.read<CategoryDetailCubit>().getCategoryDetail(widget.categoryId),
221-
);
222-
_listenForProposalRef(context.read<CategoryDetailCubit>());
220+
final cubit = context.read<CategoryDetailCubit>()..watchActiveCampaignCategories();
221+
unawaited(cubit.getCategoryDetail(widget.categoryRef));
222+
_listenForProposalRef(cubit);
223223
}
224224

225+
// TODO(damian-molinski): refactor it to signal pattern
225226
void _listenForProposalRef(CategoryDetailCubit cubit) {
226227
// listen for updates
227228
_categoryRefSub = cubit.stream
228-
.map((event) => event.category?.id)
229+
.map((event) => event.selectedCategoryRef)
229230
.distinct()
230231
.listen(_onCategoryRefChanged);
231232
}

0 commit comments

Comments
 (0)