将html模板组件存储在数据库中

I am looking for a solution to a staright forward problem:

There are some templates which are divided into parts of two types: 1. image 2. text

I call these parts as components of the template whose values are entered by the user. The image component can have a link, alt text related to it. The text component can have plain text or some lines of html. The value of these components are used to render the final output of the template.

There can be around 5-10 components for each template which may not be common for other templates, like:

pageTitle
tagline
firstParagraph
buttonText
headerImage     -   Image Component
firstImage      -   Image Component

So the simple calculation says:

  • 1 page = 1 template
  • 1 user can have > 1 pages
  • Each template can have 5-10 components

So if i store it like:

COMPONENT   TYPE        VALUE         LINK

pageTitle   text        Hello world
tagline     text        tagline here
headerImage image       image.jpg     http://example.com

And it can be any number of users, so lets say 10000 pages will have > 10000*10 components in a db!!

How can we have less number of entries and with the best performance? Better schema? Serialized? Json? File based system? or anything else... What can be done?

Thanks in advance!

100k records are not a large number, most database can handle this number

if there will be so many users(pages), any solution you mentioned will cost much resources

Well some things to keep in mind when building something like this:

  • a memory table is great for fast reads, so if you have a lot of ram I'd consider having two tables an innodb so that if your server crashes you will be able to rebuild your memory tables that and it's great cause you can role back.
  • Also make sure you make use of indexes. You need to make sure
    everything in your where statement is in an indexes and try and make all your indexes are numbers if as all possible. Perhaps have text that is going to be repeated a lot in the table be in another table, so you can use a number in the table it's needed for.
  • Another thing that helps me is more then likely the same pages are going to be hit more often, so a type of caching that will cache the pages that have been built in a set amount of time should help preformance as well.

Hope that helps.