Skip to content

Commit

Permalink
fix(sync)
Browse files Browse the repository at this point in the history
- fixes an issue where the file entry was updated with the latest fetched transaction from network, instead of comparing the date with the database
  • Loading branch information
thiagocarvalhodev committed Sep 24, 2024
1 parent ed846af commit fd03464
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:ardrive/blocs/upload/models/payment_method_info.dart';
import 'package:ardrive/blocs/upload/upload_file_checker.dart';
import 'package:ardrive/core/activity_tracker.dart';
import 'package:ardrive/core/upload/uploader.dart';
import 'package:ardrive/drive_explorer/thumbnail/repository/thumbnail_repository.dart';
import 'package:ardrive/entities/file_entity.dart';
import 'package:ardrive/entities/folder_entity.dart';
import 'package:ardrive/models/forms/cc.dart';
Expand Down Expand Up @@ -55,6 +56,7 @@ class UploadCubit extends Cubit<UploadState> {
final LicenseService _licenseService;
final ConfigService _configService;
final ARNSRepository _arnsRepository;
final ThumbnailRepository _thumbnailRepository;

late bool uploadFolders;
late Drive _targetDrive;
Expand Down Expand Up @@ -337,6 +339,7 @@ class UploadCubit extends Cubit<UploadState> {
required LicenseService licenseService,
required ConfigService configService,
required ARNSRepository arnsRepository,
required ThumbnailRepository thumbnailRepository,
this.folder,
this.uploadFolders = false,
this.isDragNDrop = false,
Expand All @@ -349,6 +352,7 @@ class UploadCubit extends Cubit<UploadState> {
_licenseService = licenseService,
_configService = configService,
_arnsRepository = arnsRepository,
_thumbnailRepository = thumbnailRepository,
_uploadThumbnail = configService.config.uploadThumbnails,
super(UploadPreparationInProgress());

Expand Down Expand Up @@ -1189,6 +1193,7 @@ class UploadCubit extends Cubit<UploadState> {
performedAction: revisionAction,
),
);

if (licensesCompanion != null) {
await _driveDao.insertLicense(licensesCompanion);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/core/upload/cost_calculator.dart';
import 'package:ardrive/core/upload/uploader.dart';
import 'package:ardrive/drive_explorer/thumbnail/repository/thumbnail_repository.dart';
import 'package:ardrive/l11n/validation_messages.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/congestion_warning_wrapper.dart';
Expand Down Expand Up @@ -177,6 +178,7 @@ Future<void> promptToUpload(
licenseService: context.read<LicenseService>(),
configService: context.read<ConfigService>(),
arnsRepository: context.read<ARNSRepository>(),
thumbnailRepository: context.read<ThumbnailRepository>(),
)..startUploadPreparation(),
),
BlocProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ class ThumbnailRepository {
Future<ThumbnailData> getThumbnail({
required FileDataTableItem fileDataTableItem,
}) async {
if (_cachedThumbnails[fileDataTableItem.id] != null) {
return _cachedThumbnails[fileDataTableItem.id]!;
if (_cachedThumbnails[fileDataTableItem.dataTxId] != null) {
return _cachedThumbnails[fileDataTableItem.dataTxId]!;
}

final drive = await _driveDao
.driveById(driveId: fileDataTableItem.driveId)
.getSingle();

if (drive.isPrivate) {
_cachedThumbnails[fileDataTableItem.id] = ThumbnailData(
_cachedThumbnails[fileDataTableItem.dataTxId] = ThumbnailData(
data: await _getThumbnailData(fileDataTableItem: fileDataTableItem),
url: null,
);

return _cachedThumbnails[fileDataTableItem.id]!;
return _cachedThumbnails[fileDataTableItem.dataTxId]!;
}

final urlString =
'${_arweaveService.client.api.gatewayUrl.origin}/raw/${fileDataTableItem.thumbnail?.variants.first.txId}';

_cachedThumbnails[fileDataTableItem.id] =
_cachedThumbnails[fileDataTableItem.dataTxId] =
ThumbnailData(data: null, url: urlString);

return _cachedThumbnails[fileDataTableItem.id]!;
return _cachedThumbnails[fileDataTableItem.dataTxId]!;
}

Future<Uint8List> _getThumbnailData({
Expand Down
8 changes: 3 additions & 5 deletions lib/sync/domain/repositories/sync_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@ class _SyncRepository implements SyncRepository {

final newRevisions = <FileRevisionsCompanion>[];
for (final entity in newEntities) {
if (entity.assignedNames != null) {
logger.d('Entity has assigned names: ${entity.assignedNames}');
}

if (!latestRevisions.containsKey(entity.id) &&
entity.parentFolderId != null) {
final revisions = await _driveDao
Expand All @@ -1022,7 +1018,9 @@ class _SyncRepository implements SyncRepository {
}

newRevisions.add(revision);
latestRevisions[entity.id!] = revision;
if (revision.dateCreated.value.isBefore(entity.createdAt)) {
latestRevisions[entity.id!] = revision;
}
} catch (e, stacktrace) {
logger.e('Error adding revision for entity', e, stacktrace);
}
Expand Down

0 comments on commit fd03464

Please sign in to comment.