Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it ok to make a request to db before validation

Let’s say I have an image upload(for users) feature for posts. This feature has some internal(for admin to decide) limits, for example allowed maximum size of the image. So now, when user uploads an image, I need to validate this parameter of allowed maximum size and for that reason I need to make a before-validation request to the database.

I’m concerned with that extra database call as at scale it may impact overall performance, but I’m really not sure if this is the case and what alternatives I have with such functionality to exist.

Would love to hear your input on that and debunk my performance concerns.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In case it might be relevant, I use node with express and mysql.

>Solution :

Yes, it’s fine to make multiple SQL calls. SQL is generally extremely fast, I doubt making one extra request here is going to make a noticeable difference at all.

It’s also worth considering that, since you’re already uploading an image, this query will be a bit slower anyway, so any extra performance hit would be even less noticeable than normal.

However, you could also consider a different approach for storing / querying this configuration, since it’s unlikely to change very often. For example, your node server could query it once from SQL when it first starts up, and then cache it locally, updating the cached value only when the query to the admin portal is made to change it. That way you can avoid making the extra SQL query when the actual upload requests come through.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading