Skip to content

Commit 3f913ca

Browse files
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
1 parent 2c4914d commit 3f913ca

File tree

62 files changed

+3141
-7525
lines changed

Some content is hidden

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

62 files changed

+3141
-7525
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ Future<void> cleanUpStorages({
182182
Future<void> cleanUpUserDataFromDatabase() async {
183183
final db = Dependencies.instance.get<CatalystDatabase>();
184184

185-
await db.draftsDao.deleteWhere();
186-
await db.favoritesDao.deleteAll();
185+
await db.localDocumentsV2Dao.deleteWhere();
186+
await db.localMetadataDao.deleteWhere();
187187
}
188188

189189
@visibleForTesting

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ final class Dependencies extends DependencyProvider {
165165
get<ProposalService>(),
166166
get<CommentService>(),
167167
get<CampaignService>(),
168+
get<DocumentsService>(),
168169
get<DocumentMapper>(),
169170
get<VotingBallotBuilder>(),
170171
get<VotingService>(),
@@ -261,11 +262,6 @@ final class Dependencies extends DependencyProvider {
261262
get<CatalystProfiler>(),
262263
);
263264
})
264-
..registerLazySingleton<DocumentFavoriteSource>(() {
265-
return DatabaseDocumentFavoriteSource(
266-
get<CatalystDatabase>(),
267-
);
268-
})
269265
..registerLazySingleton<CatGatewayDocumentDataSource>(() {
270266
return CatGatewayDocumentDataSource(
271267
get<ApiServices>(),
@@ -285,7 +281,6 @@ final class Dependencies extends DependencyProvider {
285281
get<DatabaseDraftsDataSource>(),
286282
get<DatabaseDocumentsDataSource>(),
287283
get<CatGatewayDocumentDataSource>(),
288-
get<DocumentFavoriteSource>(),
289284
);
290285
})
291286
..registerLazySingleton<DocumentMapper>(() => const DocumentMapperImpl())

catalyst_voices/docs/performance/proposals_query.csv

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ docs_count ,filer ,avg_duration ,PR ,note
3434
7008 ,categories:finals ,0:00:01.294485 ,#3622 ,-
3535
14008 ,categories ,0:00:02.108506 ,#3622 ,-
3636
14008 ,categories:drafts ,0:00:01.585000 ,#3622 ,-
37-
14008 ,categories:finals ,0:00:05.024950 ,#3622 ,-
37+
14008 ,categories:finals ,0:00:05.024950 ,#3622 ,-
38+
712 ,categories ,0:00:00.139314 ,#3747 ,-
39+
712 ,categories:drafts ,0:00:00.138364 ,#3747 ,-
40+
712 ,categories:finals ,0:00:00.148680 ,#3747 ,-
41+
7008 ,categories ,0:00:00.168405 ,#3747 ,-
42+
7008 ,categories:drafts ,0:00:00.190470 ,#3747 ,-
43+
7008 ,categories:finals ,0:00:00.167145 ,#3747 ,-
44+
14008 ,categories ,0:00:00.253610 ,#3747 ,-
45+
14008 ,categories:drafts ,0:00:00.266390 ,#3747 ,-
46+
14008 ,categories:finals ,0:00:00.247054 ,#3747 ,-

catalyst_voices/packages/internal/catalyst_voices_blocs/lib/src/proposal/proposal_cubit.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class ProposalCubit extends Cubit<ProposalState>
2525
final ProposalService _proposalService;
2626
final CommentService _commentService;
2727
final CampaignService _campaignService;
28+
final DocumentsService _documentsService;
2829
final DocumentMapper _documentMapper;
2930
final VotingBallotBuilder _ballotBuilder;
3031
final VotingService _votingService;
@@ -40,6 +41,7 @@ final class ProposalCubit extends Cubit<ProposalState>
4041
this._proposalService,
4142
this._commentService,
4243
this._campaignService,
44+
this._documentsService,
4345
this._documentMapper,
4446
this._ballotBuilder,
4547
this._votingService,
@@ -89,7 +91,7 @@ final class ProposalCubit extends Cubit<ProposalState>
8991
final commentTemplate = await _commentService.getCommentTemplateFor(
9092
category: proposal.document.metadata.categoryId,
9193
);
92-
final isFavorite = await _proposalService.watchIsFavoritesProposal(ref: ref).first;
94+
final isFavorite = await _documentsService.isFavorite(ref);
9395

9496
_cache = _cache.copyWith(
9597
proposal: Optional(proposal),

catalyst_voices/packages/internal/catalyst_voices_blocs/lib/src/proposal_builder/proposal_builder_bloc.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,22 @@ final class ProposalBuilderBloc extends Bloc<ProposalBuilderEvent, ProposalBuild
941941
emit(state.copyWith(isChanging: true));
942942
if (state.isMaxProposalsLimitReached) {
943943
final proposalSubmissionCloseDate = await _getProposalSubmissionCloseDate();
944-
final count = await _proposalService.watchUserProposalsCount().first;
944+
final activeAccountId = _userService.user.activeAccount?.catalystId;
945+
final count = activeAccountId == null
946+
? 0
947+
: await _proposalService
948+
.watchProposalsCountV2(
949+
filters: ProposalsFiltersV2(
950+
status: ProposalStatusFilter.aFinal,
951+
author: activeAccountId,
952+
),
953+
)
954+
.first;
945955

946956
if (proposalSubmissionCloseDate != null) {
947957
final signal = MaxProposalsLimitReachedSignal(
948958
proposalSubmissionCloseDate: proposalSubmissionCloseDate,
949-
currentSubmissions: count.finals,
959+
currentSubmissions: count,
950960
maxSubmissions: ProposalDocument.maxSubmittedProposalsPerUser,
951961
);
952962

catalyst_voices/packages/internal/catalyst_voices_dev/lib/src/catalyst_voices_dev.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export 'catalyst_compression/catalyst_compressor_fakes.dart';
44
export 'catalyst_key_derivation/bip32_ed25519_fakes.dart';
55
export 'catalyst_key_derivation/key_derivation_service_fakes.dart';
66
export 'catalyst_voices_models/crypto/catalyst_crypto_fakes.dart';
7-
export 'catalyst_voices_models/document/document_factories.dart';
7+
export 'catalyst_voices_models/document/document_data_factory.dart';
8+
export 'catalyst_voices_models/document/document_ref_factory.dart';
89
export 'catalyst_voices_repositories/api/api_mocks.dart';
910
export 'catalyst_voices_repositories/repository_mocks.dart';
1011
export 'catalyst_voices_repositories/user/keychain_fakes.dart';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:catalyst_voices_dev/catalyst_voices_dev.dart';
2+
import 'package:catalyst_voices_models/catalyst_voices_models.dart' hide Document;
3+
4+
abstract final class DocumentDataFactory {
5+
static DocumentData build({
6+
DocumentType type = DocumentType.proposalDocument,
7+
DocumentRef? selfRef,
8+
SignedDocumentRef? template,
9+
SignedDocumentRef? categoryId,
10+
DocumentDataContent content = const DocumentDataContent({}),
11+
}) {
12+
return DocumentData(
13+
metadata: DocumentDataMetadata(
14+
type: type,
15+
selfRef: selfRef ?? DocumentRefFactory.signedDocumentRef(),
16+
template: template,
17+
categoryId: categoryId,
18+
),
19+
content: content,
20+
);
21+
}
22+
}

catalyst_voices/packages/internal/catalyst_voices_dev/lib/src/catalyst_voices_models/document/document_factories.dart

Lines changed: 0 additions & 163 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'dart:math';
2+
3+
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
4+
import 'package:flutter/foundation.dart';
5+
import 'package:uuid_plus/uuid_plus.dart';
6+
7+
abstract final class DocumentRefFactory {
8+
static final Random _random = Random(57342052346526);
9+
static var _timestamp = DateTime.now().millisecondsSinceEpoch;
10+
11+
static DraftRef draftRef() {
12+
return DraftRef.first(randomUuidV7());
13+
}
14+
15+
static String randomUuidV7() {
16+
return const UuidV7().generate(
17+
options: V7Options(
18+
_randomDateTime().millisecondsSinceEpoch,
19+
_randomBytes(10),
20+
),
21+
);
22+
}
23+
24+
static SignedDocumentRef signedDocumentRef() {
25+
return SignedDocumentRef.first(randomUuidV7());
26+
}
27+
28+
static String uuidV7At(DateTime dateTime) {
29+
final ts = dateTime.millisecondsSinceEpoch;
30+
final rand = Uint8List.fromList([42, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
31+
return const UuidV7().generate(options: V7Options(ts, rand));
32+
}
33+
34+
static List<int> _randomBytes(int length) {
35+
return List.generate(length, (index) => _random.nextInt(256));
36+
}
37+
38+
static DateTime _randomDateTime() {
39+
final timestamp = _timestamp;
40+
_timestamp++;
41+
42+
return DateTime.fromMillisecondsSinceEpoch(timestamp);
43+
}
44+
}

catalyst_voices/packages/internal/catalyst_voices_models/lib/src/catalyst_voices_models.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ export 'proposal/proposal_or_document.dart';
9797
export 'proposal/proposal_version.dart';
9898
export 'proposal/proposal_votes.dart';
9999
export 'proposal/proposal_with_context.dart';
100-
export 'proposals/proposals_count.dart';
101-
export 'proposals/proposals_count_filters.dart';
102-
export 'proposals/proposals_filters.dart';
103100
export 'proposals/proposals_filters_v2.dart';
104101
export 'proposals/proposals_order.dart';
105102
export 'proposals/proposals_total_ask_filters.dart';

0 commit comments

Comments
 (0)