Merge pull request #21322 from overleaf/jpa-skip-converted-cleanup

[filestore] remove unnecessary cleanup of converted files

GitOrigin-RevId: a46aaee473938209dc56d9fea90f96d09952ce47
This commit is contained in:
Jakob Ackermann 2024-10-24 13:43:25 +02:00 committed by Copybot
parent 29381cf054
commit 52edad6f12
2 changed files with 34 additions and 31 deletions

View file

@ -49,9 +49,6 @@ async function insertFile(bucket, key, stream) {
convertedKey, convertedKey,
}) })
} }
if (Settings.enableConversions) {
await PersistorManager.deleteDirectory(bucket, convertedKey)
}
await PersistorManager.sendStream(bucket, key, stream) await PersistorManager.sendStream(bucket, key, stream)
} }
@ -65,7 +62,10 @@ async function deleteFile(bucket, key) {
}) })
} }
const jobs = [PersistorManager.deleteObject(bucket, key)] const jobs = [PersistorManager.deleteObject(bucket, key)]
if (Settings.enableConversions) { if (
Settings.enableConversions &&
bucket === Settings.filestore.stores.template_files
) {
jobs.push(PersistorManager.deleteDirectory(bucket, convertedKey)) jobs.push(PersistorManager.deleteDirectory(bucket, convertedKey))
} }
await Promise.all(jobs) await Promise.all(jobs)

View file

@ -67,7 +67,11 @@ describe('FileHandler', function () {
compressPng: sinon.stub().resolves(), compressPng: sinon.stub().resolves(),
}, },
} }
Settings = {} Settings = {
filestore: {
stores: { template_files: 'template_files', user_files: 'user_files' },
},
}
fs = { fs = {
createReadStream: sinon.stub().returns(readStream), createReadStream: sinon.stub().returns(readStream),
} }
@ -133,23 +137,6 @@ describe('FileHandler', function () {
done() done()
}) })
}) })
describe('when conversions are enabled', function () {
beforeEach(function () {
Settings.enableConversions = true
})
it('should delete the convertedKey folder', function (done) {
FileHandler.insertFile(bucket, key, stream, err => {
expect(err).not.to.exist
expect(PersistorManager.deleteDirectory).to.have.been.calledWith(
bucket,
convertedFolderKey
)
done()
})
})
})
}) })
describe('deleteFile', function () { describe('deleteFile', function () {
@ -195,15 +182,31 @@ describe('FileHandler', function () {
Settings.enableConversions = true Settings.enableConversions = true
}) })
it('should delete the convertedKey folder', function (done) { it('should delete the convertedKey folder for template files', function (done) {
FileHandler.deleteFile(bucket, key, err => { FileHandler.deleteFile(
expect(err).not.to.exist Settings.filestore.stores.template_files,
expect(PersistorManager.deleteDirectory).to.have.been.calledWith( key,
bucket, err => {
convertedFolderKey expect(err).not.to.exist
) expect(PersistorManager.deleteDirectory).to.have.been.calledWith(
done() Settings.filestore.stores.template_files,
}) convertedFolderKey
)
done()
}
)
})
it('should not delete the convertedKey folder for user files', function (done) {
FileHandler.deleteFile(
Settings.filestore.stores.user_files,
key,
err => {
expect(err).not.to.exist
expect(PersistorManager.deleteDirectory).to.not.have.been.called
done()
}
)
}) })
}) })
}) })