From 16cb42761e268b8734b2ff1fb7e97056bde9e4ad Mon Sep 17 00:00:00 2001 From: JAVIER SEGARRA MARTINEZ Date: Sat, 20 Jan 2024 11:22:41 +0000 Subject: [PATCH] refs #5576 perf: remove bad try/catch declarations --- back/models/image.js | 59 +++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index fd3535e46..fec52759b 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -62,10 +62,6 @@ module.exports = Self => { Self.removeLink = async(child, parent = null) => { try { await fs.unlink(child); - } catch (e) { - throw new Error(e); - } - try { await fs.symlink(parent, child); } catch (e) { throw new Error(e); @@ -75,10 +71,6 @@ module.exports = Self => { try { const exists = await fs.exists(parent); exists && await fs.unlink(parent); - } catch (e) { - throw new Error(e); - } - try { await fs.symlink(child, parent); } catch (e) { throw new Error(e); @@ -102,41 +94,36 @@ module.exports = Self => { ...baseUpsert, updated: Date.vnNow() / 1000, }); - } catch (e) { - throw new Error(e); - } - const collection = await Self.getCollection(collectionName); - const {maxWidth, maxHeight} = collection; + + const collection = await Self.getCollection(collectionName); + const {maxWidth, maxHeight} = collection; - // Update entity image file name - const model = models[collection.model]; - if (!model) throw new Error('No matching model found'); + // Update entity image file name + const model = models[collection.model]; + if (!model) throw new Error('No matching model found'); - const entity = await model.findById(entityId); - if (entity) - await entity.updateAttribute(collection.property, name); + const entity = await model.findById(entityId); + if (entity) + await entity.updateAttribute(collection.property, name); - // Resize - const collectionDir = await Self.getCollectionDir(collectionName); + // Resize + const collectionDir = await Self.getCollectionDir(collectionName); - // To max size - const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); + // To max size + const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir); - const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; - try { + const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath; + await fs.mkdir(fullSizePath, {recursive: true}); - } catch (e) { - throw new Error(e); - } - const gmInstance = gm(srcFile); - let fileWidth = null; - let fileHeight = null; + + const gmInstance = gm(srcFile); + let fileWidth = null; + let fileHeight = null; - gmInstance.size(function(err, size) { - if (err) throw new Error(err); - [fileWidth, fileHeight] = parseSize(size); - }); - try { + gmInstance.size(function(err, size) { + if (err) throw new Error(err); + [fileWidth, fileHeight] = parseSize(size); + }); await new Promise((resolve, reject) => { gmInstance .resize(maxWidth, maxHeight, '>')