Skip to content

Commit

Permalink
fix(editor): no more retry in downloading emojis
Browse files Browse the repository at this point in the history
Not needed to do that.
  • Loading branch information
realth000 committed Oct 7, 2024
1 parent 4753d44 commit aed01da
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions lib/features/editor/repository/editor_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,39 +231,23 @@ final class EditorRepository with LoggerMixin {
if (!force && cacheProvider.hasEmojiCacheFile(emojiGroup.id, emoji.id)) {
return true;
}
var retryMaxTimes = 3;
// Retry until success.
while (true) {
if (retryMaxTimes <= 0) {
error('failed to download emoji ${emojiGroup.id}_${emoji.id}: '
'exceed max retry times');
return false;
}
try {
final respEither = await netClient.getImage(emoji.url).run();
if (respEither.isLeft()) {
final err = respEither.unwrapErr();
handle(err);
throw err;
}
final resp = respEither.unwrap();
if (resp.statusCode != HttpStatus.ok) {
await Future.delayed(const Duration(milliseconds: 200), () {});
retryMaxTimes -= 1;
continue;
}
await cacheProvider.updateEmojiCache(
emojiGroup.id,
emoji.id,
resp.data as List<int>,
);
break;
} catch (e) {
await Future.delayed(const Duration(milliseconds: 200), () {});
retryMaxTimes -= 1;
continue;
}
// No more retry here.
final respEither = await netClient.getImage(emoji.url).run();
if (respEither.isLeft()) {
handle(respEither.unwrapErr());
error('failed to download emoji ${emojiGroup.id}_${emoji.id}: '
'exceed max retry times');
return false;
}
final resp = respEither.unwrap();
if (resp.statusCode != HttpStatus.ok) {
return false;
}
await cacheProvider.updateEmojiCache(
emojiGroup.id,
emoji.id,
resp.data as List<int>,
);
return true;
}

Expand Down Expand Up @@ -299,6 +283,7 @@ final class EditorRepository with LoggerMixin {
_generateDownloadEmojiTask(netClient, cacheProvider, emojiGroup, e),
);
debug('download for emoji group: ${emojiGroup.id}');
debug('emoji group ${emojiGroup.id} ${emojiGroup.emojiList.first.url}');
await Future.wait(downloadList);
}
info('load emoji from server finished');
Expand Down

0 comments on commit aed01da

Please sign in to comment.