mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-23 04:25:24 +00:00
Make use of the new cache feature of the request backend for pinejs-client 1.2.0 to make use of an ETags based cache for requests to the api.
This commit is contained in:
parent
82873d2ef2
commit
c8df0b2f9e
@ -22,7 +22,7 @@
|
||||
"pubnub": "~3.6.4",
|
||||
"randomstring": "~1.0.3",
|
||||
"request": "^2.51.0",
|
||||
"pinejs-client": "^1.0.0",
|
||||
"pinejs-client": "^1.2.0",
|
||||
"sqlite3": "~3.0.4",
|
||||
"tty.js": "~0.2.13",
|
||||
"typed-error": "~0.1.0"
|
||||
|
@ -13,7 +13,8 @@ logger = require './lib/logger'
|
||||
{docker} = dockerUtils
|
||||
|
||||
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
|
||||
resinAPI = new PlatformAPI(PLATFORM_ENDPOINT)
|
||||
resinApi = new PlatformAPI(PLATFORM_ENDPOINT)
|
||||
cachedResinApi = resinApi.clone({}, cache: {})
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
logger.init(
|
||||
@ -173,7 +174,7 @@ exports.update = update = ->
|
||||
.then ([ [ apiKey ], [ uuid ], apps ]) ->
|
||||
apiKey = apiKey.value
|
||||
uuid = uuid.value
|
||||
resinAPI.get(
|
||||
cachedResinApi.get(
|
||||
resource: 'application'
|
||||
options:
|
||||
expand: 'environment_variable'
|
||||
@ -289,7 +290,7 @@ getDeviceID = do ->
|
||||
knex('config').select('value').where(key: 'uuid')
|
||||
])
|
||||
.spread ([{value: apiKey}], [{value: uuid}]) ->
|
||||
resinAPI.get(
|
||||
resinApi.get(
|
||||
resource: 'device'
|
||||
options:
|
||||
select: 'id'
|
||||
@ -326,7 +327,7 @@ exports.updateDeviceState = updateDeviceState = do ->
|
||||
stateDiff = getStateDiff()
|
||||
if _.size(stateDiff) is 0
|
||||
return
|
||||
resinAPI.patch
|
||||
resinApi.patch
|
||||
resource: 'device'
|
||||
id: deviceID
|
||||
body: stateDiff
|
||||
|
@ -9,7 +9,7 @@ PlatformAPI = require 'pinejs-client'
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
|
||||
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
|
||||
resinAPI = new PlatformAPI(PLATFORM_ENDPOINT)
|
||||
resinApi = new PlatformAPI(PLATFORM_ENDPOINT)
|
||||
|
||||
registerDevice = (apiKey, userId, applicationId, deviceType, uuid) ->
|
||||
# I'd be nice if the UUID matched the output of a SHA-256 function, but although the length limit of the CN
|
||||
@ -19,7 +19,7 @@ registerDevice = (apiKey, userId, applicationId, deviceType, uuid) ->
|
||||
if not uuid?
|
||||
uuid = crypto.pseudoRandomBytes(31).toString('hex')
|
||||
|
||||
resinAPI.post(
|
||||
resinApi.post(
|
||||
resource: 'device'
|
||||
body:
|
||||
user: userId
|
||||
|
Loading…
x
Reference in New Issue
Block a user