Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the appropriate approach to store email templates

Is it appropriate to store a web page in a Database? I am using InnoDB engine of mysql, the email templates is a modified html files that is in mail format , so there should be a plain html file.

Notice that those templates are not accessible for everyone, they should refer to the userID, so for example, User A has template1 , 2 ,3.. but UserB may have template 2,3, 5, 6..

What datatype should i store this kind of file?

Or instead of using database, I should create a html file and use php to write in it and open a folder for each user?

Thank you for your help, I have less experience in handling this kind of data

like image 709
user782104 Avatar asked Mar 18 '12 13:03

user782104


1 Answers

Usually, and for most project, the database is the bottleneck. So, if you can avoid to use it, then don't use it. If the html is small (for example 10kb) then you can store in the database. However, if it is big (and requires BLOB or a big varchar), then save it in a file folder using the unique id of the registry, having caution about the number of templates that could exists. However, a backup of the system requires to also backup those files (instead of a single backup of the database).

User A has template1 , 2 ,3.. but UserB may have template 2,3, 5, 6..

It sound like

Table User

Id_User Name_User ...

Table Template

Id_Template Name_Template Content_Template (if it is not managed by a file) ....

Table UserxTemplate

Id_User Id_Template

Obtain the all templates by an user

 select * from User a,Template b,UserxTemplate c
 where c.id_user=a.id_user and   c.id_template=b.id_template and a.id_user=xxx

In resume

Store in the database

Pro:

  • consistence.
  • easy to use

Cons:

  • Performance hit
  • Increase of the size of the database.

Store in a file

Pro:

  • fast (only if the number of templates is not big)
  • "unlimited" size.

Cons:

  • Inconsistence of the data.
  • Requires an extra work.
  • Securities issues.

ps: Wordpress and other portal and blog system (usually) store it inside the database, however LMS (Learning Management System) stores in a file.

like image 107
magallanes Avatar answered Nov 15 '22 10:11

magallanes