codidact / qpixel

Q&A-based community knowledge-sharing software
https://codidact.com
GNU Affero General Public License v3.0
393 stars 68 forks source link

Cache HTML for posts rather than storing it in the database #1415

Open trichoplax opened 1 month ago

trichoplax commented 1 month ago

Is your feature request related to a problem? Please describe. My understanding is that currently we store a post twice in the database: once as the raw Markdown, and also as the HTML that it is converted to. This works, but causes some inconveniences:

Describe the solution you'd like Store only the raw Markdown in the database, and have caching that prevents the need for the server to recalculate the HTML each time the page is served.

Any time that caches are emptied, the server will need to recalculate the HTML for each page served, but only the first time for each page. Is there any reason to think this would be too much load?

Unlike the current approach, this would allow discarding the cached HTML for posts that have not been viewed for a long time. Old posts would not need to have their HTML stored, but would still be viewable if necessary. Old revisions of a post which are never going to be viewed as HTML again would expire from the cache.

In most cases, the HTML would be calculated at the point of saving the post (as currently), so the only difference is where the data is stored.

cellio commented 1 month ago

@ArtOfCode- could you review this request? Are there downsides we should consider, or should we go ahead and add labels and add it to the queue?