One pattern we’re trying to use at Discourse is to break up our giant
User table into several smaller tables. There are many advantages to doing this, but one obvious one is that by default in Rails if you say
User.find(1) it will load all the columns from the database by default, which can be quite expensive.
Recently I added a
location string to a User so users can optionally say where they’re from on their profile. This is definitely not a column that you want returned from the database all the time. Instead, I created a new
UserProfile model and added the field there.
Now, when you view a user’s profile, it will include the location field from that table. It works great!
However, it’s obvious that there are least a couple of other fields on
User that should be moved over to this table too:
website: the user’s personal web site
bio_cooked: their bio information
profile_backgroundtheir profile background image
Some of those fields like
website should be easier to move over than others, but I believe all should be brought over.
If anyone is looking for a Rails specific task to bring them up to speed with Discourse, this might be a good one to try! Of course we’d an expect a pull request that does this to:
- Works properly
- Includes a migration to move old data over so nothing is lost
- Pass tests
- Add more tests if necessary for coverage (some of those fields might not be tested)
We are also not against smaller PRs that don’t do the whole task. For example if you just want to move
website and not bother with the other two, that’s totally fine.
Feel free to ask questions/comments here if you’re interested. Thanks!