Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload duration logic #281

Closed
wants to merge 6 commits into from

Conversation

parveshneedhoo
Copy link
Contributor

No description provided.

Comment on lines 23 to 24
database.execSQL("ALTER TABLE upload_events ADD COLUMN uploadDuration INTEGER NOT NULL DEFAULT 0");
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of storing uploadDuration, why don't we store the startTime and endTime. The uploadDuration is calculated from these values. Normally it is better to save the values from which it calculated rather than the value itself. (Example saving the date of birth in a db rather than the age as age can be calculated with the dob)

If we save the the starting and ending times, we can then calculate the uploadDuration and return it alongside the ending time also to the JS and set our uploadedAt to the returned ending time value.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

DOB is saved instead of age because age changes, here the uploadDuration will not change. I agree that we need to send the uploadedAt value also but I think it is better that we calculate the uploadDuration on the plugin side which will be calculated immediately after the upload instead of waiting for the JS side to wait for the values to do the calculations.

Copy link
Member

Choose a reason for hiding this comment

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

Yes my suggestion was to calculate the uploadDuration on the plugin side itself and not calculate it on the JS side but to save the values from which we derive the uploadDuration in the db and return the uploadDuration AND the uploadedAt time also.

I gave the age as an example. Other examples can be keeping the buyingPrice and sellingPrice then derive the profitfrom it althought the profit won't change. In this case the uploadDuration won't change but saving the start and end times gives more information than just the uploadDuration.

Comment on lines 23 to 24
database.execSQL("ALTER TABLE upload_events ADD COLUMN uploadDuration INTEGER NOT NULL DEFAULT 0");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

DOB is saved instead of age because age changes, here the uploadDuration will not change. I agree that we need to send the uploadedAt value also but I think it is better that we calculate the uploadDuration on the plugin side which will be calculated immediately after the upload instead of waiting for the JS side to wait for the values to do the calculations.

public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE upload_events ADD COLUMN uploadDuration INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE upload_events ADD COLUMN startUploadTime INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE upload_events ADD COLUMN endUploadTime INTEGER NOT NULL DEFAULT 0");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
database.execSQL("ALTER TABLE upload_events ADD COLUMN endUploadTime INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE upload_events ADD COLUMN finishUploadTime INTEGER NOT NULL DEFAULT 0");

NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
configuration.HTTPMaximumConnectionsPerHost = FileUploader.parallelUploadsLimit;
configuration.sessionSendsLaunchEvents = NO;
self.manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
__weak FileUploader *weakSelf = self;
[self.manager setTaskDidCompleteBlock:^(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSError * _Nullable error) {
NSString* uploadId = [NSURLProtocol propertyForKey:kUploadUUIDStrPropertyKey inRequest:task.originalRequest];
NSDate *startTime = weakSelf.uploadStartTimes[uploadId];
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startTime];
Copy link
Contributor

Choose a reason for hiding this comment

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

The format/accuracy is same as android?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants