Ask an old question about batch release.

topic description

the above problem can not be avoided is that there are two copies of the data, such as an article being edited in the background and an article that the user is browsing. How to achieve the amount of data modification, the data takes up the least amount of space. If you look at the article alone, such as the article table, it is easier to deal with the problem and back up the data. For example, when you need to edit an article, set up a backup data for the article, and the backup data is modified in the background, so that it does not affect the browsing of the foreground users. When the background is modified, click publish, and the backup data overwrites the original data, while deleting the backup data, which is a bit like the bak file in Linux. This is the case with additions, deletions and modifications. Of course, this idea can also be used in reverse, creating a quick backup data, directly modifying the original data in the background, and users browsing the backup data. In this way, the logic of user browsing needs to be dealt with specially. Here is a single table, this way of thinking can be solved. But if it is multi-table data, such as articles have categories, entertainment articles, news articles, etc., how to deal with data linkage when editing article categories. A little more articles have one or more tags, such as piece articles and lace articles. Three meters linkage, all need to maintain the change state. In this case, the way you just added backup data over there will be extremely complicated. I don"t know if the great gods in the jar have any good ideas.

sources of topics and their own ideas

here, we have done a two-table linkage data before, and there are two roles that are somewhat similar to articles and tags. An article has one or more tags. The landlord designed three tables, article tables and label tables. The article <-> tag relation table is linked by the tag and the article <-> tag relation table. when adding, deleting or changing the tag, the relationship table is linked at the same time, and the background modification is completed and released uniformly.
the owner backs up both the tag and the relational table. When the tag is modified, the tag backup data is added and linked at the same time. The tag data in the relational table will be backed up anyway. When deleting, it is the same as modifying. Add the simplest, only need to add label backup, there is no data processing in the relational table. The middle involves the addition and deletion of the original data and the deletion and modification of the backup data. I have done a lot of work, and I deeply feel that I have been fooled by the plan I designed.

there are other ideas, too.
for example, the landlord has thought about designing double fields when designing a table, just like a thing from both positive and negative sides, the positive side is for others to see, and the negative side is for others to see. In that case, there is only one piece of data, an id, in the data table. It"s easy to maintain, and the flaw is field redundancy.
there are also extremely violent practices, two similar tables, which are somewhat similar to the idea of the above method and are equally redundant.

Oct.09,2021

after practice, it is recommended to create two identical tables. One table has a marked status field, and the same table and table can be changed by Synchronize directly. The above two methods, in the data association of multiple tables, the business processing is very troublesome, it is easy to have bug.


The problem of

subject should be the problem of reader and writer. the common method is to add mutex lock, read-write lock, data version and so on. The above analysis of the subject should belong to the write-time replication technology, such as CopyOnWriteList in Java , that is, in the process of updating the data, a fraction of the data is copied and updated, and then written back after the update is completed. It is really troublesome to write back, and the subject can do it in a different way, such as

.
A:Id
B:1
C:2
ABBA[1,'B']CBA[1,'C']
CopyOnWriteList

method 2: add read-write lock, read-write mutual exclusion
when an article needs to be changed after publication, it is necessary to unpublish the article, so that the article cannot be read in the update process, thus achieving the purpose of mutual exclusion. But this method has a poor user experience.

method 3: data version
the subject can study the MVCC of the database. For example, the isolation level of MySQL is achieved with MVCC . He can ensure that the internal update of each thing does not affect other transactions. Similarly, you can use the same method here to ensure that the update of data does not affect the reading of other users. The logic of this method is relatively simple, and you only need to add three fields to OK.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b2e3-2babd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b2e3-2babd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?