Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add monitoring and management to uploads #531

Merged
merged 25 commits into from
Sep 4, 2018

Conversation

pauldemarco
Copy link
Contributor

This PR uses similar techniques found in other firebase plugins to add management and monitoring of uploads (StorageUploadTask) to Firebase Storage.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@pauldemarco
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@szakarias
Copy link
Contributor

Thank you very much for your contribution.

It is great with the file split of firebase_storage.dart. For review purposes, please do it separately in its own PR either before or after the change. Also please make sure all the tests, format, analyze etc. pass.

@pauldemarco
Copy link
Contributor Author

pauldemarco commented May 7, 2018 via email

@szakarias
Copy link
Contributor

In order to do the review, please rebase and fix the conflicts and failing tests.

@pauldemarco pauldemarco force-pushed the firebase-storage-uploadtask branch from b7d8155 to a808b4b Compare May 9, 2018 15:51
Copy link
Contributor

@szakarias szakarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the first batch of comments.

In addition, please focus this PR on the relevant change. That is, remove all the unnecessary style and format changes such as renaming, reordering, etc.

@required StorageReference reference,
StorageMetadata metadata,
}) : _storage = storage,
_reference = reference,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for changing the argument from path to a storageReference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code similarity with repo.

final FirebaseStorage _firebaseStorage;
final String _path;
StorageUploadTask({
@required FirebaseStorage storage,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change to named parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code similarity with repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style changes should be done separately.

abstract class StorageUploadTask {
final FirebaseStorage _firebaseStorage;
final String _path;
StorageUploadTask({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor should remain private.


/// Returns a StorageTaskSnapshot on complete, or throws error
Future<StorageTaskSnapshot> _start() async {
_handle = await _platformMethod().then<int>((dynamic result) => result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just _handle = await _platformMethod();

/// Returns a StorageTaskSnapshot on complete, or throws error
Future<StorageTaskSnapshot> _start() async {
_handle = await _platformMethod().then<int>((dynamic result) => result);
return await _storage._methodStream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for await since you are returning a Future.

The multiple stream transformations makes the code hard to read. Let's try with a single where and a single map like this

final StorageTaskEvent event = await _storage._methodStream
      .where(...)
      .map((MethodCall call) {...})
      .firstWhere(...);
return event.snapshot;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rather prefer the multiple .where and .map to break out the transformation steps whilst using the fat arrow notation. Is there a performance benefit to combining into code blocks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is definitely a performance overhead in having several transformation, but the main issue here is readability. You could also try with some helper functions that encapsulate the logic you want to express.

String path, StorageMetadata metadata)
: super._(firebaseStorage, path, metadata);
class _StorageFileUploadTask extends StorageUploadTask {
_StorageFileUploadTask({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the constructor signature unless it is functionally needed.

String path, StorageMetadata metadata)
: super._(firebaseStorage, path, metadata);
class _StorageDataUploadTask extends StorageUploadTask {
_StorageDataUploadTask({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above regarding constructor signature change.

StorageFileUploadTask._(this._file, FirebaseStorage firebaseStorage,
String path, StorageMetadata metadata)
: super._(firebaseStorage, path, metadata);
class _StorageFileUploadTask extends StorageUploadTask {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this class private is a breaking change. Let's leave it public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to do this? This will introduce some ambiguity for the end user. Why expose StorageFileUploadTask and StorageDataUploadTask when the only functionality that would be needed is found in the base class, StorageUploadTask?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide on this, it should be done in a separate PR.

StorageDataUploadTask._(this._bytes, FirebaseStorage firebaseStorage,
String path, StorageMetadata metadata)
: super._(firebaseStorage, path, metadata);
class _StorageDataUploadTask extends StorageUploadTask {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this public too.

@@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Cloud Storage, a powerful, simple, and
cost-effective object storage service for Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_storage
version: 0.3.4
version: 0.3.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it ends up being a breaking change, increment the minor version instead.

@Hixie
Copy link
Contributor

Hixie commented May 29, 2018

@pauldemarco Will you be able to continue working on this? It's totally fine if not; we can take it over (though it might take longer). I'm just asking because I'm trying to clean out our review queue.

@pauldemarco
Copy link
Contributor Author

pauldemarco commented May 29, 2018

Hi @Hixie, yep i've got some time carved out later this week for this.

@pauldemarco
Copy link
Contributor Author

@szakarias Many of those formatting and internal changes were to increase code similarity between other plugins in this repo, like FirebaseDatabase and CloudFirestore.

I'll take a look at what might be unnecessary and revert, as well as apply those other requests later this week.

Thanks!

StorageFileUploadTask._(this._file, FirebaseStorage firebaseStorage,
String path, StorageMetadata metadata)
: super._(firebaseStorage, path, metadata);
class _StorageFileUploadTask extends StorageUploadTask {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide on this, it should be done in a separate PR.

/// Returns a StorageTaskSnapshot on complete, or throws error
Future<StorageTaskSnapshot> _start() async {
_handle = await _platformMethod().then<int>((dynamic result) => result);
return await _storage._methodStream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is definitely a performance overhead in having several transformation, but the main issue here is readability. You could also try with some helper functions that encapsulate the logic you want to express.

final FirebaseStorage _firebaseStorage;
final String _path;
StorageUploadTask({
@required FirebaseStorage storage,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style changes should be done separately.

// found in the LICENSE file.
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our license header should say Chromium Authors

@pauldemarco pauldemarco force-pushed the firebase-storage-uploadtask branch 4 times, most recently from 674dc7a to c0d4317 Compare June 4, 2018 03:23
@pauldemarco
Copy link
Contributor Author

@szakarias I reverted a bunch of styling changes, and applied the changes for _setState.

It's unclear whether it's the PR author's responsibility to update the CHANGELOG and pubspec version, so I left it alone for now.

Let me know of anything else.

Thanks!

@szakarias
Copy link
Contributor

Thanks for your update.

I can see you removed the example code. Could you update the example again to exercise some of the new features?

Also going forward, please don't squash commits as this makes reviewing harder.

@Hixie
Copy link
Contributor

Hixie commented Jun 26, 2018

@pauldemarco Please let us know if you be able to continue working on this. If you don't have an opportunity to do so that's totally fine, we will in due course fix the remaining issues and land the patch. Thanks for your contributions so far!

@pauldemarco
Copy link
Contributor Author

@Hixie @szakarias I'll be able to include a cleaned up example this week, thanks for your patience.

@pauldemarco pauldemarco force-pushed the firebase-storage-uploadtask branch 2 times, most recently from a6da37d to dd52c7a Compare July 3, 2018 18:16
@kroikie kroikie force-pushed the firebase-storage-uploadtask branch from ec250fe to 22df07d Compare August 25, 2018 00:12
@googlebot
Copy link

CLAs look good, thanks!

Copy link
Contributor

@kroikie kroikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pauldemarco Once you remove the unnecessary 'CANCELLED' print, I think this is good to merge.

break;
case StorageTaskEventType.failure:
isComplete = true;
print('CANCELLED');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this print statement.

@kroikie kroikie merged commit cd60fb0 into flutter:master Sep 4, 2018
nichtverstehen pushed a commit to nichtverstehen/plugins that referenced this pull request Sep 6, 2018
* Upload monitoring and management added for Android and iOS.
@Hixie Hixie removed the needs love label Oct 24, 2018
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
* Upload monitoring and management added for Android and iOS.
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
* Upload monitoring and management added for Android and iOS.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants