Ma-Kas / kansaibeyond

Monorepo for a blog and travel website, consisting of frontend, backend, and headless cms.
https://www.kansaibeyond.com
0 stars 0 forks source link

Media storage implementation #16

Closed Ma-Kas closed 5 months ago

Ma-Kas commented 7 months ago

Would it be best to create a media table that holds information on the media used? E.g columns name, url, alt

This table could then be queried against the blog_id to get all media relevant to specific blog.

PRO: Centralized, easy to implement an image picker of sorts when editing CON: more joins could slow down blog loading.

Or is current approach better with blog having a direct media column that stringifies a dictionary of media within that blog, that is merely to store name/url to fetch from image storage service?

PRO: Faster access, allows image urls to directly be copied instead of having to upload and go through table CON: Decentralized

A mix of both, where a media table could be used for an image picker when writing/editing blog, but then whatever is actually added to the blog, gets saved to the media column in the blog table?

PRO: Fast access, centralized CON: Doubling of information, two sources of truth

Ma-Kas commented 7 months ago

CDN: Store name of the image in db rather than the full URL, and get the base URL from configuration (e.g http://whatever/ as base, imagename.jpg in DB) If ever move images to other storage provider, won't have to update every record in db.

Ma-Kas commented 6 months ago

This seems to be the way. Additionally, append any transformations to the image url at the last moment e.g after database fetch and in img src for maximum flexibility