[shotwell: 1/4] split uploads into batches of 50
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell: 1/4] split uploads into batches of 50
- Date: Tue, 17 Aug 2021 18:33:23 +0000 (UTC)
commit a63753cf321d74d7393b74430060219a8720813d
Author: Phred <fearphage gmail com>
Date: Wed Jun 23 13:04:57 2021 -0500
split uploads into batches of 50
plugins/shotwell-publishing/PhotosPublisher.vala | 50 +++++++++++++++---------
1 file changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/plugins/shotwell-publishing/PhotosPublisher.vala
b/plugins/shotwell-publishing/PhotosPublisher.vala
index 5f464700..8c4e6e7b 100644
--- a/plugins/shotwell-publishing/PhotosPublisher.vala
+++ b/plugins/shotwell-publishing/PhotosPublisher.vala
@@ -7,6 +7,7 @@
namespace Publishing.GooglePhotos {
internal const string DEFAULT_ALBUM_NAME = N_("Shotwell Connect");
+internal const int MAX_BATCH_SIZE = 50;
internal class Album {
public string name;
@@ -127,28 +128,39 @@ private class MediaCreationTransaction : Publishing.RESTSupport.GooglePublisher.
}
public override void execute () throws Spit.Publishing.PublishingError {
- var builder = new Json.Builder();
- builder.begin_object();
- builder.set_member_name("albumId");
- builder.add_string_value(this.album_id);
- builder.set_member_name("newMediaItems");
- builder.begin_array();
- for (var i = 0; i < this.upload_tokens.length; i++) {
- builder.begin_object();
- builder.set_member_name("description");
- builder.add_string_value(this.titles[i]);
- builder.set_member_name("simpleMediaItem");
+ for (var h = 0; h * MAX_BATCH_SIZE < this.upload_tokens.length; h++) {
+ var offset = h * MAX_BATCH_SIZE;
+ var difference = this.upload_tokens.length - offset;
+ if (difference > MAX_BATCH_SIZE) {
+ end = offset + MAX_BATCH_SIZE;
+ }
+ else {
+ end = offset + difference;
+ }
+
+ var builder = new Json.Builder();
builder.begin_object();
- builder.set_member_name("uploadToken");
- builder.add_string_value(this.upload_tokens[i]);
- builder.end_object();
+ builder.set_member_name("albumId");
+ builder.add_string_value(this.album_id);
+ builder.set_member_name("newMediaItems");
+ builder.begin_array();
+ for (var i = offset; i < end; i++) {
+ builder.begin_object();
+ builder.set_member_name("description");
+ builder.add_string_value(this.titles[i]);
+ builder.set_member_name("simpleMediaItem");
+ builder.begin_object();
+ builder.set_member_name("uploadToken");
+ builder.add_string_value(this.upload_tokens[i]);
+ builder.end_object();
+ builder.end_object();
+ }
+ builder.end_array();
builder.end_object();
- }
- builder.end_array();
- builder.end_object();
- set_custom_payload(Json.to_string (builder.get_root (), false), "application/json");
+ set_custom_payload(Json.to_string (builder.get_root (), false), "application/json");
- base.execute();
+ base.execute();
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]