This is the SQL which appears to be very slow. It's taking about 6 seconds and is pulling back all 330,000 records in the database on my dev server. I'm not sure what it is doing but could it be modified to bring back only top x rows?
exec sp_executesql N'SELECT "dbo"."yaf_Message"."MessageID" AS "ID", "dbo"."yaf_Message"."TopicID", "dbo"."yaf_Message"."ReplyTo", "dbo"."yaf_Message"."Position", "dbo"."yaf_Message"."Indent", "dbo"."yaf_Message"."UserID", "dbo"."yaf_Message"."UserName", "dbo"."yaf_Message"."Posted", "dbo"."yaf_Message"."Message" AS "MessageText", "dbo"."yaf_Message"."IP", "dbo"."yaf_Message"."Edited", "dbo"."yaf_Message"."Flags", "dbo"."yaf_Message"."EditReason", "dbo"."yaf_Message"."IsModeratorChanged", "dbo"."yaf_Message"."DeleteReason", "dbo"."yaf_Message"."EditedBy", "dbo"."yaf_Message"."ExternalMessageId", "dbo"."yaf_Message"."ReferenceMessageId", "dbo"."yaf_Message"."UserDisplayName"
FROM "dbo"."yaf_Topic" INNER JOIN "dbo"."yaf_Message" ON ("dbo"."yaf_Message"."TopicID" = "dbo"."yaf_Topic"."TopicID")
WHERE ((("dbo"."yaf_Topic"."ForumID" = @0) AND (("dbo"."yaf_Topic"."Flags" & @1) <> @2)) AND (("dbo"."yaf_Message"."Flags" & @3) = @4))
ORDER BY "dbo"."yaf_Message"."Posted" DESC',N'@0 int,@1 int,@2 int,@3 int,@4 int',@0=2,@1=8,@2=8,@3=24,@4=16
Further testing shows that the message is inserted into the database very quickly.
If I open another browser and login as a different user I can see the new message before the browser which I am posting from refreshes. So the slowdown is happening after the database insert.
Edit: I've identified the code causing the slowdown. It is in YAF.Core\Model\MessageRepositoryExtensions.cs and I comment out the lines below the performance is massively improved. However, I'm not really sure what that code does and whether it is needed?
if (flags.IsApproved)
{
repository.Approve(newMessageId, forum.ID);
BoardContext.Current.Get<IRaiseEvent>;().Raise(new UpdateForumStatsEvent(forum.ID));
}
Edit 2: It's the update to the forum stats which is causing the problems. Commenting out as below makes a massive difference to posting time.
BoardContext.Current.Get<IRaiseEvent>().Raise(new UpdateForumStatsEvent(forumId));
in AF.Core\Model\MessageRepositoryExtensions.cs:
public static Message SaveNew
public static void Approve
Edited by user
4 months ago
|
Reason: Not specified