Ver Fonte

Improve types and export functions we want to use

GitOrigin-RevId: 25fd93214f88c425bee23d43de113cf754f89524
Andrew Rumble há 1 ano atrás
pai
commit
392037efd6

+ 1 - 1
services/history-v1/api/controllers/with_tmp_dir.js

@@ -9,7 +9,7 @@ const path = require('node:path')
  * after.
  * after.
  *
  *
  * @param {string} prefix - prefix for the temporary directory name
  * @param {string} prefix - prefix for the temporary directory name
- * @param {Function} fn - async function to call
+ * @param {(tmpDir: string) => Promise<void>} fn - async function to call
  */
  */
 async function withTmpDir(prefix, fn) {
 async function withTmpDir(prefix, fn) {
   const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), prefix))
   const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), prefix))

+ 1 - 1
services/history-v1/storage/lib/blob_hash.js

@@ -63,7 +63,7 @@ exports.fromString = function blobHashFromString(string) {
  * Compute the git blob hash for the content of a file
  * Compute the git blob hash for the content of a file
  *
  *
  * @param  {string} filePath
  * @param  {string} filePath
- * @return {string} hexadecimal SHA-1 hash
+ * @return {Promise<string>} hexadecimal SHA-1 hash
  */
  */
 exports.fromFile = function blobHashFromFile(pathname) {
 exports.fromFile = function blobHashFromFile(pathname) {
   assert.string(pathname, 'blobHash: bad pathname')
   assert.string(pathname, 'blobHash: bad pathname')

+ 7 - 0
services/history-v1/storage/lib/blob_store/index.js

@@ -24,6 +24,7 @@ const logger = require('@overleaf/logger')
 
 
 /** @import { Readable } from 'stream' */
 /** @import { Readable } from 'stream' */
 
 
+/** @type {Map<string, { blob: core.Blob, demoted: boolean}>} */
 const GLOBAL_BLOBS = new Map()
 const GLOBAL_BLOBS = new Map()
 
 
 function makeGlobalKey(hash) {
 function makeGlobalKey(hash) {
@@ -343,6 +344,11 @@ class BlobStore {
     return blob
     return blob
   }
   }
 
 
+  /**
+   *
+   * @param {Array<string>} hashes
+   * @return {Promise<*[]>}
+   */
   async getBlobs(hashes) {
   async getBlobs(hashes) {
     assert.array(hashes, 'bad hashes')
     assert.array(hashes, 'bad hashes')
     const nonGlobalHashes = []
     const nonGlobalHashes = []
@@ -427,6 +433,7 @@ module.exports = {
   getProjectBlobsBatch,
   getProjectBlobsBatch,
   loadGlobalBlobs,
   loadGlobalBlobs,
   makeProjectKey,
   makeProjectKey,
+  makeGlobalKey,
   makeBlobForFile,
   makeBlobForFile,
   getStringLengthOfFile,
   getStringLengthOfFile,
   GLOBAL_BLOBS,
   GLOBAL_BLOBS,

+ 1 - 1
services/history-v1/storage/scripts/backup.mjs

@@ -915,7 +915,7 @@ async function compareBackups(projectId, options) {
           const globalBlob = GLOBAL_BLOBS.get(blob.hash)
           const globalBlob = GLOBAL_BLOBS.get(blob.hash)
           console.log(
           console.log(
             `  ✓ Blob ${blob.hash} is a global blob`,
             `  ✓ Blob ${blob.hash} is a global blob`,
-            globalBlob.demoted ? '(demoted)' : ''
+            globalBlob?.demoted ? '(demoted)' : ''
           )
           )
           continue
           continue
         }
         }