mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #15445 from overleaf/jpa-history-v1-gzip-in-place
[history-v1] gzip chunk string in-place before passing to object layer GitOrigin-RevId: db5ded0b0db32757ed35c31c77d190bc121711a7
This commit is contained in:
parent
0ae174a47b
commit
1dc2bd3a24
2 changed files with 12 additions and 5 deletions
|
@ -103,11 +103,11 @@ HistoryStore.prototype.storeRaw = function historyStoreStoreRaw(
|
|||
assert.object(rawHistory, 'bad rawHistory')
|
||||
|
||||
const key = getKey(projectId, chunkId)
|
||||
const stream = streams.gzipStringToStream(JSON.stringify(rawHistory))
|
||||
|
||||
logger.debug({ projectId, chunkId }, 'storeRaw started')
|
||||
return BPromise.resolve()
|
||||
.then(() =>
|
||||
.then(() => streams.gzipStringToStream(JSON.stringify(rawHistory)))
|
||||
.then(stream =>
|
||||
persistor.sendStream(BUCKET, key, stream, {
|
||||
contentType: 'application/json',
|
||||
contentEncoding: 'gzip',
|
||||
|
|
|
@ -79,8 +79,15 @@ function gunzipStreamToBuffer(readStream) {
|
|||
exports.gunzipStreamToBuffer = gunzipStreamToBuffer
|
||||
|
||||
function gzipStringToStream(string) {
|
||||
const gzip = zlib.createGzip()
|
||||
return new ReadableString(string).pipe(gzip)
|
||||
return new BPromise(function (resolve, reject) {
|
||||
zlib.gzip(Buffer.from(string), function (error, result) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(new ReadableString(result))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,6 +95,6 @@ function gzipStringToStream(string) {
|
|||
*
|
||||
* @function
|
||||
* @param {string} string
|
||||
* @return {stream.Writable}
|
||||
* @return {Promise.<stream.Readable>}
|
||||
*/
|
||||
exports.gzipStringToStream = gzipStringToStream
|
||||
|
|
Loading…
Reference in a new issue