From 8966d9e4e8cc3a7ba1037681ba8d653df25c99a1 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Tue, 17 Nov 2020 00:50:56 +0300 Subject: [PATCH 1/4] Partly update fields with PATCH requests --- cvat-core/src/session.js | 92 +++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/cvat-core/src/session.js b/cvat-core/src/session.js index 26483cc19af8..aec3d9a32a25 100644 --- a/cvat-core/src/session.js +++ b/cvat-core/src/session.js @@ -674,6 +674,11 @@ task: undefined, }; + let dirtyFields = { + assignee: false, + status: false, + }; + for (const property in data) { if (Object.prototype.hasOwnProperty.call(data, property)) { if (property in initialData) { @@ -715,6 +720,7 @@ if (assignee !== null && !(assignee instanceof User)) { throw new ArgumentError('Value must be a user instance'); } + dirtyFields.assignee = true; data.assignee = assignee; }, }, @@ -743,6 +749,7 @@ ); } + dirtyFields.status = true; data.status = status; }, }, @@ -776,6 +783,12 @@ task: { get: () => data.task, }, + __dirtyFields: { + get: () => dirtyFields, + set: (fields) => { + dirtyFields = fields; + }, + }, }), ); @@ -879,6 +892,13 @@ use_cache: undefined, }; + let dirtyFields = { + name: false, + assignee: false, + bug_tracker: false, + labels: false, + }; + for (const property in data) { if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) { data[property] = initialData[property]; @@ -948,6 +968,7 @@ if (!value.trim().length) { throw new ArgumentError('Value must not be empty'); } + dirtyFields.name = true; data.name = value; }, }, @@ -1006,6 +1027,7 @@ if (assignee !== null && !(assignee instanceof User)) { throw new ArgumentError('Value must be a user instance'); } + dirtyFields.assignee = true; data.assignee = assignee; }, }, @@ -1039,6 +1061,7 @@ bugTracker: { get: () => data.bug_tracker, set: (tracker) => { + dirtyFields.bug_tracker = true; data.bug_tracker = tracker; }, }, @@ -1145,6 +1168,7 @@ } } + dirtyFields.labels = true; data.labels = [...labels]; }, }, @@ -1311,6 +1335,12 @@ dataChunkType: { get: () => data.data_compressed_chunk_type, }, + __dirtyFields: { + get: () => dirtyFields, + set: (fields) => { + dirtyFields = fields; + }, + }, }), ); @@ -1443,12 +1473,30 @@ Job.prototype.save.implementation = async function () { // TODO: Add ability to change an assignee if (this.id) { - const jobData = { - status: this.status, - assignee_id: this.assignee ? this.assignee.id : null, - }; + const jobData = {}; + + for (const [field, isDirty] of Object.entries(this.__dirtyFields)) { + if (isDirty) { + switch (field) { + case 'status': + jobData.status = this.status; + break; + case 'assignee': + jobData.assignee_id = this.assignee ? this.assignee.id : null; + break; + default: + break; + } + } + } await serverProxy.jobs.saveJob(this.id, jobData); + + this.__dirtyFields = { + status: false, + assignee: false, + }; + return this; } @@ -1653,14 +1701,38 @@ // TODO: Add ability to change an owner and an assignee if (typeof this.id !== 'undefined') { // If the task has been already created, we update it - const taskData = { - assignee_id: this.assignee ? this.assignee.id : null, - name: this.name, - bug_tracker: this.bugTracker, - labels: [...this.labels.map((el) => el.toJSON())], - }; + const taskData = {}; + + for (const [field, isDirty] of Object.entries(this.__dirtyFields)) { + if (isDirty) { + switch (field) { + case 'assignee': + taskData.assignee_id = this.assignee ? this.assignee.id : null; + break; + case 'name': + taskData.name = this.name; + break; + case 'bugTracker': + taskData.bug_tracker = this.bugTracker; + break; + case 'labels': + taskData.labels = [...this.labels.map((el) => el.toJSON())]; + break; + default: + break; + } + } + } await serverProxy.tasks.saveTask(this.id, taskData); + + this.dirtyFields = { + assignee: false, + name: false, + bugTracker: false, + labels: false, + }; + return this; } From 374f3306046de0d9a2682af583f5d3179f3e17ea Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Tue, 17 Nov 2020 00:58:08 +0300 Subject: [PATCH 2/4] Added CHANGELOG and versions --- CHANGELOG.md | 2 +- cvat-core/package-lock.json | 2 +- cvat-core/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb9c68ec398c..57b9cb892c53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- +- PATCH requests from cvat-core submit only changed fields () ### Deprecated diff --git a/cvat-core/package-lock.json b/cvat-core/package-lock.json index 52e1e13811d5..10541c46426a 100644 --- a/cvat-core/package-lock.json +++ b/cvat-core/package-lock.json @@ -1,6 +1,6 @@ { "name": "cvat-core", - "version": "3.9.0", + "version": "3.9.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/cvat-core/package.json b/cvat-core/package.json index 84140ddef9a3..bbb559549bcd 100644 --- a/cvat-core/package.json +++ b/cvat-core/package.json @@ -1,6 +1,6 @@ { "name": "cvat-core", - "version": "3.9.0", + "version": "3.9.1", "description": "Part of Computer Vision Tool which presents an interface for client-side integration", "main": "babel.config.js", "scripts": { From 65df3c989a43a1530ed0108b4e37e540c1c02693 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Tue, 17 Nov 2020 09:20:05 +0300 Subject: [PATCH 3/4] Fixed setting bugTracker field --- cvat-core/src/session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cvat-core/src/session.js b/cvat-core/src/session.js index aec3d9a32a25..1e6059a06fbd 100644 --- a/cvat-core/src/session.js +++ b/cvat-core/src/session.js @@ -1712,7 +1712,7 @@ case 'name': taskData.name = this.name; break; - case 'bugTracker': + case 'bug_tracker': taskData.bug_tracker = this.bugTracker; break; case 'labels': From c1efd370f900ec1431cb1fd942b49f2d0e629468 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Wed, 18 Nov 2020 17:43:23 +0300 Subject: [PATCH 4/4] Renamed dirty -> updated --- cvat-core/src/session.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cvat-core/src/session.js b/cvat-core/src/session.js index 1e6059a06fbd..fba1a2ab1e0b 100644 --- a/cvat-core/src/session.js +++ b/cvat-core/src/session.js @@ -674,7 +674,7 @@ task: undefined, }; - let dirtyFields = { + let updatedFields = { assignee: false, status: false, }; @@ -720,7 +720,7 @@ if (assignee !== null && !(assignee instanceof User)) { throw new ArgumentError('Value must be a user instance'); } - dirtyFields.assignee = true; + updatedFields.assignee = true; data.assignee = assignee; }, }, @@ -749,7 +749,7 @@ ); } - dirtyFields.status = true; + updatedFields.status = true; data.status = status; }, }, @@ -783,10 +783,10 @@ task: { get: () => data.task, }, - __dirtyFields: { - get: () => dirtyFields, + __updatedFields: { + get: () => updatedFields, set: (fields) => { - dirtyFields = fields; + updatedFields = fields; }, }, }), @@ -892,7 +892,7 @@ use_cache: undefined, }; - let dirtyFields = { + let updatedFields = { name: false, assignee: false, bug_tracker: false, @@ -968,7 +968,7 @@ if (!value.trim().length) { throw new ArgumentError('Value must not be empty'); } - dirtyFields.name = true; + updatedFields.name = true; data.name = value; }, }, @@ -1027,7 +1027,7 @@ if (assignee !== null && !(assignee instanceof User)) { throw new ArgumentError('Value must be a user instance'); } - dirtyFields.assignee = true; + updatedFields.assignee = true; data.assignee = assignee; }, }, @@ -1061,7 +1061,7 @@ bugTracker: { get: () => data.bug_tracker, set: (tracker) => { - dirtyFields.bug_tracker = true; + updatedFields.bug_tracker = true; data.bug_tracker = tracker; }, }, @@ -1168,7 +1168,7 @@ } } - dirtyFields.labels = true; + updatedFields.labels = true; data.labels = [...labels]; }, }, @@ -1335,10 +1335,10 @@ dataChunkType: { get: () => data.data_compressed_chunk_type, }, - __dirtyFields: { - get: () => dirtyFields, + __updatedFields: { + get: () => updatedFields, set: (fields) => { - dirtyFields = fields; + updatedFields = fields; }, }, }), @@ -1475,8 +1475,8 @@ if (this.id) { const jobData = {}; - for (const [field, isDirty] of Object.entries(this.__dirtyFields)) { - if (isDirty) { + for (const [field, isUpdated] of Object.entries(this.__updatedFields)) { + if (isUpdated) { switch (field) { case 'status': jobData.status = this.status; @@ -1492,7 +1492,7 @@ await serverProxy.jobs.saveJob(this.id, jobData); - this.__dirtyFields = { + this.__updatedFields = { status: false, assignee: false, }; @@ -1703,8 +1703,8 @@ // If the task has been already created, we update it const taskData = {}; - for (const [field, isDirty] of Object.entries(this.__dirtyFields)) { - if (isDirty) { + for (const [field, isUpdated] of Object.entries(this.__updatedFields)) { + if (isUpdated) { switch (field) { case 'assignee': taskData.assignee_id = this.assignee ? this.assignee.id : null; @@ -1726,7 +1726,7 @@ await serverProxy.tasks.saveTask(this.id, taskData); - this.dirtyFields = { + this.updatedFields = { assignee: false, name: false, bugTracker: false,