mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
[web] display project history blob size on admin pages (#28351)
* [history-v1] add endpoint for getting blob stats of projects * [web] display project history blob size on admin pages * [web] break down history storage size by text and binary blob GitOrigin-RevId: bfa4d56cf2c503d03005c13a0f7ac38158156cd2
This commit is contained in:
@@ -25,6 +25,8 @@ const render = require('./render')
|
||||
const expressify = require('./expressify')
|
||||
const withTmpDir = require('./with_tmp_dir')
|
||||
const StreamSizeLimit = require('./stream_size_limit')
|
||||
const { getProjectBlobsBatch } = require('../../storage/lib/blob_store')
|
||||
const assert = require('../../storage/lib/assert')
|
||||
|
||||
const pipeline = promisify(Stream.pipeline)
|
||||
|
||||
@@ -378,6 +380,40 @@ async function getSnapshotAtVersion(projectId, version) {
|
||||
return snapshot
|
||||
}
|
||||
|
||||
function sumUpByteLength(blobs) {
|
||||
return blobs.reduce((sum, blob) => sum + blob.getByteLength(), 0)
|
||||
}
|
||||
|
||||
async function getProjectBlobsStats(req, res) {
|
||||
const projectIds = req.swagger.params.body.value.projectIds
|
||||
const { blobs } = await getProjectBlobsBatch(
|
||||
projectIds.map(id => {
|
||||
if (assert.POSTGRES_ID_REGEXP.test(id)) {
|
||||
return parseInt(id, 10)
|
||||
} else {
|
||||
return id
|
||||
}
|
||||
})
|
||||
)
|
||||
const sizes = []
|
||||
for (const projectId of projectIds) {
|
||||
const projectBlobs = blobs.get(projectId) || []
|
||||
const textBlobs = projectBlobs.filter(b => b.getStringLength() !== null)
|
||||
const binaryBlobs = projectBlobs.filter(b => b.getStringLength() === null)
|
||||
const textBlobBytes = sumUpByteLength(textBlobs)
|
||||
const binaryBlobBytes = sumUpByteLength(binaryBlobs)
|
||||
sizes.push({
|
||||
projectId,
|
||||
textBlobBytes,
|
||||
binaryBlobBytes,
|
||||
totalBytes: textBlobBytes + binaryBlobBytes,
|
||||
nTextBlobs: textBlobs.length,
|
||||
nBinaryBlobs: binaryBlobs.length,
|
||||
})
|
||||
}
|
||||
res.json(sizes)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initializeProject: expressify(initializeProject),
|
||||
getLatestContent: expressify(getLatestContent),
|
||||
@@ -396,4 +432,5 @@ module.exports = {
|
||||
getProjectBlob: expressify(getProjectBlob),
|
||||
headProjectBlob: expressify(headProjectBlob),
|
||||
copyProjectBlob: expressify(copyProjectBlob),
|
||||
getProjectBlobsStats: expressify(getProjectBlobsStats),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user