Search code examples
databasegrailsdatabase-normalization

User Image/Profile fields - Database normalization - Social Networking - Grails


Should I normalize the users profile_image_url links and the fields e.g. profile_background_color that users can customize their profiles?

Have one single User class with everything.

class User {

  String profile_big_url
  String profile_thumb_url

  String profile_background_color
  String profile_text_color
  String profile_link_color
  String profile_sidebar_fill_color
  String profile_sidebar_border_color
  String profile_background_image_url
  String profile_background_tile

}

Or three classes

class User{

   Photo photo
   Profile profile

}

class Photo{
   User user   
   String profile_big_url
   String profile_thumb_url
}

class Profile{
   User user
   String profile_background_color
   String profile_text_color
   String profile_link_color
   String profile_sidebar_fill_color
   String profile_sidebar_border_color
   String profile_background_image_url
   String profile_background_tile
}

Which is better regarding scale, performance, modification?


Solution

  • I wouldn't worry about it. Splitting the tables results in smaller selects but these are just short strings, so the cost of pulling in more data than you need is minor. Joins can be expensive, but again, these would be simple ones.

    An alternative would be to leave everything in one table, but split the class logically into three just in the code, using components. See http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.2.2%20Composition%20in%20GORM