0

I am working on a Facebook-alike app (ASP.NET MVC). Based on the number of likes on an entry, there are different badges to be assigned: On the 5th like, Badge A should be assigned, on the 10th like, Badge B should be assigned, and so forth.

However, I need to query the database in every user like to see if there is any suitable badge to assign. For example, in the 4th like event, I need to check if there is a badge that requires 4 likes, and I need to assign it.

When a liking occurs, in the application code I need to check if the entry has 4 likes, and assign the badge with db.BadgeAssignments.Add(new badge info goes here) when a liking occurs.

I wonder if it is better I do this automatically using the SQL Database Management Studio? When an entry receives the 5th like, etc., a new record can be added to the BadgeAssignment table. Does this make sense? This could be better in terms of performance, but I feel like it will be more tedious.

What would be the recommended approach in this?

renakre
  • 8,001
  • 5
  • 46
  • 99
  • Provide some schema details on tables involved and how heavily you inserts are updates are going to hapen – TheGameiswar Apr 29 '16 at 18:44
  • 1
    Whether you do this using code in you app or using triggers will have negligible impact on performance assuming you doing it in a single transaction and readability of your code is more important. What would give you better performance is to cache some of the information. For example the badges and associated number of 'likes' required to earn it could be in `MemoryCache` assuming it wont change often, and the number of likes a user has made could be stored in `Session` –  Apr 30 '16 at 05:13

0 Answers0