X
X
x2bool2012-02-08 08:53:12
SQL
x2bool, 2012-02-08 08:53:12

Article preview implementation?

Hello. It was necessary to implement a preview (partial display of the article). It can be compared with Habr: on the main page there is a somewhat truncated article; when you click on the link - the full version! How to design an implementation in SQL?
At the moment there are three ideas:

  1. Store the article in one cell along with the label (habracut). If necessary, split into two parts
  2. Store the article in two cells. If necessary, combine into one
  3. Store the article in one cell. Parse on first save. Store the label position in a separate cell. If necessary, split into two according to the saved position of the label

I'm leaning towards option #3. Intuitively, it seems that the variant should be the most productive. What do you think? Maybe there are other options?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
P
Progrik, 2012-02-08
@Progrik

If the size of the database is not critical, then 2, but without a connection (that is, in the first cell, the announcement, in the second, the entire article).
If the time it takes to pull the necessary articles from the database and cut them in half is not critical, then 3.
Personally, I use the 2nd option and do not feel remorse.

I
ikra, 2012-02-08
@ikra

What nonsense?! Of course, two fields are enough: article_anounce and article_text.

V
Vitaly Zheltyakov, 2012-02-08
@VitaZheltyakov

I see I am not fully understood, so I will describe in more detail.
- We need a table with fields: id and anounce.
- We display blocks of text with this information on the main page. Click to open the article with the required id.
- We take the entire article from a file called .php
Advantages:
- We do not load it with heavy DBMS queries. There are fewer requests.
- Opcacher itself caches articles. Without any dances with a tambourine.

V
Vitaly Zheltyakov, 2012-02-08
@VitaZheltyakov

The most productive option would be to store the article in a file, and store only a link to the file in the database.

J
jj_killer, 2012-02-08
@jj_killer

And for the first point, try this:
SUBSTRING(`text`, 1, (INSTR(`text`, "[habracut]")-1))

E
Evengard, 2012-02-08
@Evengard

Two fields. In one - only what is up to the mark of the kata. The second is the entire article (as well as what is before the kata mark, and after).
Of course, data duplication is obtained. But if CPU is more important to you than hard disk space, then why not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question