From c72b308bb9697d27b56312444fdf7253f52e716f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adria=CC=81n=20Escoms?= Date: Mon, 13 Apr 2020 11:30:37 +0200 Subject: [PATCH 1/3] fix:add throtle to avoid overrate the GitLab API --- Dockerfile | 2 +- package.json | 4 ++-- src/models/base.js | 57 ++++++++++++++++++++++++++-------------------- yarn.lock | 49 --------------------------------------- 4 files changed, 35 insertions(+), 77 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8259bb0..43e5fde 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:8.2.1-alpine -ENV GTT_VERSION 1.7.39 +ENV GTT_VERSION 1.7.40 RUN yarn global add --prefix /usr/local "gitlab-time-tracker@$GTT_VERSION" diff --git a/package.json b/package.json index 8dc55e8..db6bad5 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlab-time-tracker", - "version": "1.7.39", + "version": "1.7.40", "description": "A command line interface for GitLabs time tracking feature.", "bugs": { "url": "https://github.com/kriskbx/gitlab-time-tracker/issues" @@ -53,10 +53,10 @@ "progress": "^2.0.0", "prompt": "^1.0.0", "read-yaml": "^1.1.0", - "request": "^2.87.0", "request-promise-native": "^1.0.4", "shelljs": "^0.8.3", "tempfile": "^2.0.0", + "throttled-queue": "^1.0.7", "underscore": "^1.9.1", "xdg-basedir": "^3.0.0", "xlsx": "^0.13.5" diff --git a/src/models/base.js b/src/models/base.js index a7ca006..a1fed8f 100755 --- a/src/models/base.js +++ b/src/models/base.js @@ -2,6 +2,9 @@ const request = require('request-promise-native'); const url = require('url'); const async = require('async'); const crypto = require('crypto'); +const throttledQueue = require('throttled-queue'); + +const throttle = throttledQueue(10, 10000, true); /** * base model @@ -36,19 +39,21 @@ class base { data.private_token = this.token; return new Promise((resolve, reject) => { - request.post(`${this.url}${path}`, { - json: true, - body: data, - insecure: this._insecure, - proxy: this._proxy, - resolveWithFullResponse: true, - headers: { - 'PRIVATE-TOKEN': this.token - } - }).then(response => { - if (this.config.get('_createDump')) this.setDump(response, key); - resolve(response); - }).catch(e => reject(e)); + throttle(() => { + request.post(`${this.url}${path}`, { + json: true, + body: data, + insecure: this._insecure, + proxy: this._proxy, + resolveWithFullResponse: true, + headers: { + 'PRIVATE-TOKEN': this.token + } + }).then(response => { + if (this.config.get('_createDump')) this.setDump(response, key); + resolve(response); + }).catch(e => reject(e)); + }) }); } @@ -67,18 +72,20 @@ class base { path += `&page=${page}&per_page=${perPage}`; return new Promise((resolve, reject) => { - request(`${this.url}${path}`, { - json: true, - insecure: this._insecure, - proxy: this._proxy, - resolveWithFullResponse: true, - headers: { - 'PRIVATE-TOKEN': this.token - } - }).then(response => { - if (this.config.get('_createDump')) this.setDump(response, key); - resolve(response); - }).catch(e => reject(e)); + throttle(() => { + request(`${this.url}${path}`, { + json: true, + insecure: this._insecure, + proxy: this._proxy, + resolveWithFullResponse: true, + headers: { + 'PRIVATE-TOKEN': this.token + } + }).then(response => { + if (this.config.get('_createDump')) this.setDump(response, key); + resolve(response); + }).catch(e => reject(e)); + }) }); } diff --git a/yarn.lock b/yarn.lock index 2da1b0d..6d3966a 100755 --- a/yarn.lock +++ b/yarn.lock @@ -2012,30 +2012,6 @@ request-promise-native@^1.0.4: stealthy-require "^1.1.0" tough-cookie ">=2.3.3" -request@2.79.0: - version "2.79.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de" - dependencies: - aws-sign2 "~0.6.0" - aws4 "^1.2.1" - caseless "~0.11.0" - combined-stream "~1.0.5" - extend "~3.0.0" - forever-agent "~0.6.1" - form-data "~2.1.1" - har-validator "~2.0.6" - hawk "~3.1.3" - http-signature "~1.1.0" - is-typedarray "~1.0.0" - isstream "~0.1.2" - json-stringify-safe "~5.0.1" - mime-types "~2.1.7" - oauth-sign "~0.8.1" - qs "~6.3.0" - stringstream "~0.0.4" - tough-cookie "~2.3.0" - tunnel-agent "~0.4.1" - uuid "^3.0.0" request@^2.81.0: version "2.85.0" @@ -2064,31 +2040,6 @@ request@^2.81.0: tunnel-agent "^0.6.0" uuid "^3.1.0" -request@^2.87.0: - version "2.87.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" - dependencies: - aws-sign2 "~0.7.0" - aws4 "^1.6.0" - caseless "~0.12.0" - combined-stream "~1.0.5" - extend "~3.0.1" - forever-agent "~0.6.1" - form-data "~2.3.1" - har-validator "~5.0.3" - http-signature "~1.2.0" - is-typedarray "~1.0.0" - isstream "~0.1.2" - json-stringify-safe "~5.0.1" - mime-types "~2.1.17" - oauth-sign "~0.8.2" - performance-now "^2.1.0" - qs "~6.5.1" - safe-buffer "^5.1.1" - tough-cookie "~2.3.3" - tunnel-agent "^0.6.0" - uuid "^3.1.0" - request@~2.88.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" From 4a825b13f55d2a4a6a7ff4ccde54a20c2fad1c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adria=CC=81n=20Escoms?= Date: Mon, 27 Apr 2020 15:49:44 +0200 Subject: [PATCH 2/3] Adjust throttle rate --- src/models/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/base.js b/src/models/base.js index a1fed8f..ea057f8 100755 --- a/src/models/base.js +++ b/src/models/base.js @@ -4,7 +4,7 @@ const async = require('async'); const crypto = require('crypto'); const throttledQueue = require('throttled-queue'); -const throttle = throttledQueue(10, 10000, true); +const throttle = throttledQueue(10, 1000, true); /** * base model From be958a239cc7e28e0b344aec111ca26a1afab847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adria=CC=81n=20Escoms?= Date: Wed, 12 May 2021 10:14:57 +0200 Subject: [PATCH 3/3] Only get the updated issues from the selected date (if exists) in order to reduce the amount of issues to get from GL. --- src/models/report.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/models/report.js b/src/models/report.js index c5fad8f..4935581 100755 --- a/src/models/report.js +++ b/src/models/report.js @@ -48,6 +48,10 @@ class report extends Base { params.push(`milestone=${this.config.get('milestone')}`); } + if (this.config.get('from')) { + params.push(`updated_after=${this.config.get('from')}`) + } + return `?${params.join('&')}`; }