Skip to content

Commit

Permalink
Merge pull request #1855 from ardriveapp/PE-6743
Browse files Browse the repository at this point in the history
PE-6743: increase page size syncing arns names and get from cache
  • Loading branch information
thiagocarvalhodev authored Sep 13, 2024
2 parents 5d0962f + aaaf00d commit 2b42268
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 34 deletions.
5 changes: 5 additions & 0 deletions lib/arns/domain/arns_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ class _ARNSRepository implements ARNSRepository {
if (_getARNSUndernamesCompleter != null) {
return _getARNSUndernamesCompleter!.future;
}
logger.d('Loading names');
final date = DateTime.now();

_getARNSUndernamesCompleter = Completer();

Expand Down Expand Up @@ -244,6 +246,9 @@ class _ARNSRepository implements ARNSRepository {

lastUpdated = DateTime.now();

logger.d(
'Names loaded in ${DateTime.now().difference(date).inMilliseconds}ms');

_getARNSUndernamesCompleter!.complete(records);

_getARNSUndernamesCompleter = null;
Expand Down
4 changes: 0 additions & 4 deletions lib/arns/presentation/assign_name_bloc/assign_name_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ class AssignNameBloc extends Bloc<AssignNameEvent, AssignNameState> {
emit(LoadingNames());

final walletAddress = await _auth.getWalletAddress();
if (!event.updateARNSRecords) {
await _arnsRepository.waitForARNSRecordsToUpdate();
}

final names = await _arnsRepository.getAntRecordsForWallet(
walletAddress!,
update: event.updateARNSRecords,
);

if (names.isEmpty) {
Expand Down
15 changes: 3 additions & 12 deletions lib/blocs/create_manifest/create_manifest_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {
// Private manifests need more consideration and are currently unavailable
emit(CreateManifestPrivacyMismatch());
}

// updates the ARNS records
_arnsRepository.getAntRecordsForWallet(
_auth.currentUser.walletAddress,
update: true,
);
}

void selectUploadMethod(
Expand Down Expand Up @@ -98,10 +92,8 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {
) async {
final revisionConfirmationState = state as CreateManifestRevisionConfirm;

final arns = await _arnsRepository.getAntRecordsForWallet(
_auth.currentUser.walletAddress,
update: false,
);
final arns = await _arnsRepository
.getAntRecordsForWallet(_auth.currentUser.walletAddress);

if (arns.isNotEmpty) {
emit(
Expand Down Expand Up @@ -181,8 +173,7 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {

Future<void> checkNameConflicts(String name) async {
final arns = await _arnsRepository.getAntRecordsForWallet(
_auth.currentUser.walletAddress,
update: false,
_auth.currentUser.walletAddress
);

final parentFolder =
Expand Down
5 changes: 1 addition & 4 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ class UploadCubit extends Cubit<UploadState> {
Future<void> startUploadPreparation({
bool isRetryingToPayWithTurbo = false,
}) async {
_arnsRepository.getAntRecordsForWallet(
_auth.currentUser.walletAddress,
update: true,
);
_arnsRepository.getAntRecordsForWallet(_auth.currentUser.walletAddress);

files.removeWhere((file) => filesNamesToExclude.contains(file.ioFile.name));
_targetDrive = await _driveDao.driveById(driveId: driveId).getSingle();
Expand Down
2 changes: 1 addition & 1 deletion packages/ario_sdk/web/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129805,7 +129805,7 @@ async function $6efb768676258e07$var$getProcesses(address) {
});
arnsEmitter.fetchProcessesOwnedByWallet({
address: address,
pageSize: 100
pageSize: 10000
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ario_sdk/web/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ario_sdk/web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async function getProcesses(address) {

arnsEmitter.fetchProcessesOwnedByWallet({
address: address,
pageSize: 100
pageSize: 10000
});
});
}
22 changes: 12 additions & 10 deletions test/arns/presentation/assign_name_bloc/assign_name_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void main() {

when(() => mockAuth.getWalletAddress())
.thenAnswer((_) async => walletAddress);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress,
update: true)).thenAnswer((_) async => antRecords);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress))
.thenAnswer((_) async => antRecords);

// Act
assignNameBloc.add(const LoadNames());
Expand All @@ -74,8 +74,9 @@ void main() {
);

verify(() => mockAuth.getWalletAddress()).called(1);
verify(() => mockArnsRepository.getAntRecordsForWallet(walletAddress,
update: true)).called(1);
verify(() => mockArnsRepository.getAntRecordsForWallet(
walletAddress,
)).called(1);
});

test(
Expand All @@ -87,8 +88,8 @@ void main() {

when(() => mockAuth.getWalletAddress())
.thenAnswer((_) async => walletAddress);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress,
update: true)).thenAnswer((_) async => antRecords);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress))
.thenAnswer((_) async => antRecords);

// Act
assignNameBloc.add(const LoadNames());
Expand All @@ -103,8 +104,9 @@ void main() {
);

verify(() => mockAuth.getWalletAddress()).called(1);
verify(() => mockArnsRepository.getAntRecordsForWallet(walletAddress,
update: true)).called(1);
verify(() => mockArnsRepository.getAntRecordsForWallet(
walletAddress,
)).called(1);
});
});

Expand Down Expand Up @@ -294,8 +296,8 @@ void main() {

when(() => mockAuth.getWalletAddress())
.thenAnswer((_) async => walletAddress);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress,
update: true)).thenAnswer((_) async => antRecords);
when(() => mockArnsRepository.getAntRecordsForWallet(walletAddress))
.thenAnswer((_) async => antRecords);
when(() => mockArnsRepository.setUndernamesToFile(
undername: any(named: 'undername'),
fileId: any(named: 'fileId'),
Expand Down
2 changes: 1 addition & 1 deletion web/js/ario_sdk.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b42268

Please sign in to comment.