diff --git a/MyApp.ServiceInterface/Data/AppConfig.cs b/MyApp.ServiceInterface/Data/AppConfig.cs index 7454ae1..b7e8b12 100644 --- a/MyApp.ServiceInterface/Data/AppConfig.cs +++ b/MyApp.ServiceInterface/Data/AppConfig.cs @@ -107,24 +107,24 @@ public void Init(IDbConnection db) public void UpdateUsersReputation(IDbConnection db) { - db.ExecuteNonQuery(@"update UserInfo set Reputation = UserScores.total - from (select createdBy, sum(count) as total from - (select createdBy, count(*) as count from post where CreatedBy is not null group by 1 - union - select userName, count(*) as count from vote group by 1 - union - select substring(id,instr(id,'-')+1) as userName, sum(UpVotes) as count from StatTotals where instr(id,'-') group by 1 - union - select substring(id,instr(id,'-')+1) as userName, sum(DownVotes) as count from StatTotals where instr(id,'-') group by 1) - group by 1) as UserScores - where UserName = UserScores.CreatedBy"); + db.ExecuteNonQuery(@"UPDATE UserInfo SET Reputation = UserScores.total + FROM (SELECT CreatedBy, sum(count) as total FROM + (SELECT CreatedBy, count(*) as count FROM post WHERE CreatedBy IS NOT NULL GROUP BY 1 + UNION + SELECT UserName, count(*) as count FROM Vote GROUP BY 1 + UNION + SELECT CreatedBy, sum(UpVotes) as count FROM StatTotals WHERE CreatedBy IS NOT NULL GROUP BY 1 + UNION + SELECT CreatedBy, sum(DownVotes) as count FROM StatTotals WHERE CreatedBy IS NOT NULL GROUP BY 1) + GROUP BY 1) as UserScores + WHERE UserName = UserScores.CreatedBy"); } public void UpdateUsersQuestions(IDbConnection db) { - db.ExecuteNonQuery(@"update UserInfo set QuestionsCount = UserQuestions.total - from (select createdBy, count(*) as total from post where CreatedBy is not null group by 1) as UserQuestions - where UserName = UserQuestions.CreatedBy"); + db.ExecuteNonQuery(@"UPDATE UserInfo SET QuestionsCount = UserQuestions.total + FROM (select createdBy, count(*) as total FROM post WHERE CreatedBy IS NOT NULL GROUP BY 1) as UserQuestions + WHERE UserName = UserQuestions.CreatedBy"); } public void ResetInitialPostId(IDbConnection db) diff --git a/MyApp/Migrations/Migration1000.cs b/MyApp/Migrations/Migration1000.cs index 35ab164..eb72fe3 100644 --- a/MyApp/Migrations/Migration1000.cs +++ b/MyApp/Migrations/Migration1000.cs @@ -160,6 +160,7 @@ public override void Up() Db.CreateTable(); Db.ExecuteSql("INSERT INTO UserInfo (UserId, UserName) SELECT Id, UserName FROM AspNetUsers"); + Db.ExecuteSql("UPDATE StatTotals SET CreatedBy = substr(Id,instr(Id,'-')+1) WHERE instr(Id,'-') > 0 AND CreatedBy IS NULL"); } public override void Down()