1

I'm building a bookmarking feature, allowing users to place a marker inside a blog post. The data will then be saved in the database, and retrieved upon opening that blog post.

The same concept can be applied for a lot of things in WordPress, like post ratings, post favoriting, etc. So far I've been creating new MySQL tables (approach 2) for these features, but now I'm second guessing myself.

The two options of approach:

1. Using the native wp_usermeta table

This would require serializing a list of post ID's and marker positions, and then storing them inside the wp_usermeta table as a string. Using this method seems the easiest, but I'm not sure how this would affect the performance of the wp_usermeta table. Especially considering the serialized data could be potentially large.

2. Creating a new table

With this option I would not have to serialize the data, but every new marker would get it's own row, which would have to have the user_id, post_id, and maybe a timestamp inside.

What is the most efficient method of approach?

I would like to know which of these method is preferred, considering things like performance, scalability, compatibility, and ease of use. Or perhaps there is a better method than these two?

3

Normalizing data is more efficient, and storing serialized data in a table field that you want to search / work with on DB level isn't something for Non-Nosql RDBMS like MySQL/MariaDB. Searching those fields is inefficient, you can't use indexes on it, can't join on it, and it's generally painful to develop imho. If you've stored that data in a PHP serialized blob, you'll have to load every row in order to examine it, because the database can't do that work for you (or write very ugly regexps, that may explode if anybody ever feels like adding other data to that field).

That said, unless you have larger amounts of data, you probably won't "feel" the inefficiency in wall clock seconds on simple queries, and it might be easier to work with user meta fields, depending on how experienced your developers (or those that will be in charge of it after you deliver it) are with databases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.