Use more cached MemberData
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
@inherits Umbraco.Web.Mvc.UmbracoViewPage<OurUmbraco.Forum.Models.ReadOnlyComment>
|
||||
@inherits UmbracoViewPage<OurUmbraco.Forum.Models.ReadOnlyComment>
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using OurUmbraco.Forum.Services
|
||||
@using OurUmbraco.Powers.Library
|
||||
|
||||
@{
|
||||
var currentMember = Members.GetCurrentMember();
|
||||
var currentMember = Model.MemberData != null && Model.MemberData.Member != null ? Model.MemberData.Member : null;
|
||||
var answer = (int)ViewData["answer"];
|
||||
var roles = new List<string>();
|
||||
|
||||
@@ -14,14 +13,14 @@
|
||||
{
|
||||
roles = commentAuthor.GetRoles();
|
||||
}
|
||||
var topicService = new TopicService(ApplicationContext.DatabaseContext);
|
||||
var topic = topicService.CurrentTopic(this.Context, ApplicationContext.ApplicationCache.RequestCache);
|
||||
var forum = Umbraco.TypedContent(topic.ParentId);
|
||||
|
||||
var topicParentId = (int)ViewData["topicParentId"];
|
||||
var forum = Umbraco.TypedContent(topicParentId);
|
||||
var forumReadOnly = forum.NewTopicsAllowed() == false;
|
||||
|
||||
}
|
||||
@* If author exists and comment is either not spam or the viewer is a the author or an admin admin *@
|
||||
@if (commentAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == commentAuthor.Id) || Members.IsAdmin()))
|
||||
@if (commentAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == commentAuthor.Id) || Model.MemberData != null && Model.MemberData.IsAdmin))
|
||||
{
|
||||
<li class="comment @(Model.ParentCommentId > 0 ? "level-2" : null) @(Model.Id == answer ? "solution" : null)" data-parent="@Model.ParentCommentId" id="comment-@Model.Id">
|
||||
<div class="meta">
|
||||
@@ -68,7 +67,7 @@
|
||||
<div class="highfive-count votes-tooltip" title="@(Model.Votes.Any() ? html : null)">
|
||||
@Model.Score
|
||||
</div>
|
||||
@if (Members.IsLoggedIn() && !Utils.HasVoted(currentMember.Id, Model.Id, "powersComment"))
|
||||
@if (Model.MemberData != null && !Utils.HasVoted(currentMember.Id, Model.Id, "powersComment"))
|
||||
{
|
||||
if (currentMember.Id != Model.MemberId)
|
||||
{
|
||||
@@ -82,7 +81,7 @@
|
||||
@if (Model.IsSpam)
|
||||
{
|
||||
<div class="alert">
|
||||
@if (Members.IsAdmin())
|
||||
@if (Model.MemberData.IsAdmin)
|
||||
{
|
||||
<span>You can see this comment because you're a moderator of the forum.</span><br/><br/>
|
||||
}
|
||||
@@ -97,13 +96,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
@if (Members.IsLoggedIn())
|
||||
@if (Model.MemberData != null)
|
||||
{
|
||||
<a href="#" class="flag-comment" data-id="@Model.Id" data-member="@currentMember.Id">
|
||||
<i class="icon-Flag"></i><span>Flag as spam</span>
|
||||
</a>
|
||||
|
||||
if (answer == 0 && (Members.IsAdmin() || currentMember.Id == Model.TopicAuthorId))
|
||||
if (answer == 0 && (Model.MemberData.IsAdmin || currentMember.Id == Model.TopicAuthorId))
|
||||
{
|
||||
<a href="#" class="solved" data-id="@Model.Id">
|
||||
<i class="icon-Check"></i><span>Mark as solution</span>
|
||||
@@ -124,7 +123,7 @@
|
||||
</a>
|
||||
}
|
||||
|
||||
if (Members.IsAdmin() || currentMember.Id == Model.MemberId)
|
||||
if (Model.MemberData.IsAdmin || currentMember.Id == Model.MemberId)
|
||||
{
|
||||
<a href="#" class="edit-post" data-id="@Model.Id" data-topic="@Model.TopicId" data-controller="comment">
|
||||
<i class="icon-Edit"></i><span>Edit</span>
|
||||
@@ -134,7 +133,7 @@
|
||||
<i class="icon-Delete-key"></i><span>Delete</span>
|
||||
</a>
|
||||
|
||||
if (Members.IsAdmin())
|
||||
if (Model.MemberData.IsAdmin)
|
||||
{
|
||||
if (Model.IsSpam)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
@inherits Umbraco.Web.Mvc.UmbracoViewPage<OurUmbraco.Forum.Models.Topic>
|
||||
@inherits UmbracoViewPage<OurUmbraco.Forum.Models.Topic>
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using OurUmbraco.Powers.Library
|
||||
|
||||
@{
|
||||
var currentMember = Members.GetCurrentMember();
|
||||
var currentMember = Model.MemberData != null && Model.MemberData.Member != null ? Model.MemberData.Member : null;
|
||||
var topicAuthor = Members.GetById(Model.MemberId);
|
||||
|
||||
@* If author exists and question is either not spam or the viewer is a the author or an admin admin *@
|
||||
if (topicAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == topicAuthor.Id) || Members.IsAdmin()))
|
||||
if (topicAuthor != null && (Model.IsSpam == false || (currentMember != null && currentMember.Id == topicAuthor.Id) || Model.MemberData != null && Model.MemberData.IsAdmin))
|
||||
{
|
||||
var forum = Umbraco.TypedContent(Model.ParentId);
|
||||
var roles = topicAuthor.GetRoles();
|
||||
@@ -50,7 +50,7 @@
|
||||
<div class="highfive-count votes-tooltip" title="@(Model.Votes.Any() ? html : null)">
|
||||
@Model.Score
|
||||
</div>
|
||||
@if (Members.IsLoggedIn() && !Utils.HasVoted(currentMember.Id, Model.Id, "powersTopic"))
|
||||
@if (Model.MemberData != null && !Utils.HasVoted(currentMember.Id, Model.Id, "powersTopic"))
|
||||
{
|
||||
if (currentMember.Id != Model.MemberId)
|
||||
{
|
||||
@@ -82,7 +82,7 @@
|
||||
@if (Model.IsSpam)
|
||||
{
|
||||
<div class="alert">
|
||||
@if (Members.IsAdmin())
|
||||
@if (Model.MemberData != null && Model.MemberData.IsAdmin)
|
||||
{
|
||||
<span>You can see this topic because you're a moderator of the forum.</span><br/><br/>
|
||||
}
|
||||
@@ -98,7 +98,7 @@
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
@if (Members.IsLoggedIn())
|
||||
@if (Model.MemberData != null)
|
||||
{
|
||||
<a href="#" class="flag-thread" data-id="@Model.Id" data-member="@currentMember.Id">
|
||||
<i class="icon-Flag"></i><span>Flag as spam</span>
|
||||
@@ -111,7 +111,7 @@
|
||||
</a>
|
||||
}
|
||||
|
||||
if (Members.IsAdmin() || Members.GetCurrentMember().Id == topicAuthor.Id)
|
||||
if (Model.MemberData.IsAdmin || Model.MemberData.Member.Id == topicAuthor.Id)
|
||||
{
|
||||
<a href="#" class="edit-post" data-id="@Model.Id" data-controller="topic">
|
||||
<i class="icon-Edit"></i><span>Edit</span>
|
||||
@@ -122,7 +122,7 @@
|
||||
</a>
|
||||
}
|
||||
|
||||
if (Members.IsAdmin())
|
||||
if (Model.MemberData.IsAdmin)
|
||||
{
|
||||
if (Model.IsSpam)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
@{
|
||||
var topicService = new TopicService(ApplicationContext.DatabaseContext);
|
||||
var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache);
|
||||
var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache, MemberData);
|
||||
|
||||
var notification = Model.Content.GetPropertyValue<string>("mainNotification");
|
||||
if (string.IsNullOrWhiteSpace(notification))
|
||||
@@ -78,8 +78,9 @@
|
||||
@foreach (var comment in topic.Comments.Where(x => x.ParentCommentId == 0))
|
||||
{
|
||||
var comm = comment;
|
||||
comm.MemberData = MemberData;
|
||||
|
||||
Html.RenderPartial("forum/comment", comm, new ViewDataDictionary { { "level", 1 }, { "answer", topic.Answer } });
|
||||
Html.RenderPartial("forum/comment", comm, new ViewDataDictionary { { "level", 1 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId } });
|
||||
|
||||
if (comm.HasChildren)
|
||||
{
|
||||
@@ -87,7 +88,7 @@
|
||||
|
||||
foreach (var child in children.Where(c => c.ParentCommentId == comm.Id))
|
||||
{
|
||||
Html.RenderPartial("forum/comment", child, new ViewDataDictionary { { "level", 2 }, { "answer", topic.Answer } });
|
||||
Html.RenderPartial("forum/comment", child, new ViewDataDictionary { { "level", 2 }, { "answer", topic.Answer }, { "topicParentId", topic.ParentId } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage
|
||||
@{
|
||||
var topicService = new TopicService(ApplicationContext.DatabaseContext);
|
||||
var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache);
|
||||
var topic = topicService.CurrentTopic(Context, ApplicationContext.ApplicationCache.RequestCache, MemberData);
|
||||
}
|
||||
|
||||
<div class="utility-actions">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using OurUmbraco.Our.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
|
||||
namespace OurUmbraco.Forum.Models
|
||||
@@ -43,6 +43,8 @@ namespace OurUmbraco.Forum.Models
|
||||
[Column("hasChildren")]
|
||||
public bool HasChildren { get; set; }
|
||||
|
||||
public MemberData MemberData { get; set; }
|
||||
|
||||
public List<SimpleMember> Votes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OurUmbraco.Our.Models;
|
||||
using umbraco;
|
||||
using Umbraco.Core.Persistence;
|
||||
|
||||
@@ -58,6 +59,8 @@ namespace OurUmbraco.Forum.Models
|
||||
[Column("version")]
|
||||
public int Version { get; set; }
|
||||
|
||||
public MemberData MemberData { get; set; }
|
||||
|
||||
public List<SimpleMember> Votes { get; set; }
|
||||
|
||||
public string GetUrl()
|
||||
|
||||
@@ -338,23 +338,27 @@ WHERE forumTopics.id=@id
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="cache"></param>
|
||||
/// <param name="memberData"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// So that we don't have to look this up multiple times in a single request, this will use the given ICacheProvider to cache it
|
||||
/// </remarks>
|
||||
public ReadOnlyTopic CurrentTopic(HttpContextBase context, ICacheProvider cache)
|
||||
public ReadOnlyTopic CurrentTopic(HttpContextBase context, ICacheProvider cache, MemberData memberData)
|
||||
{
|
||||
return (ReadOnlyTopic)cache.GetCacheItem(typeof(TopicService) + "-CurrentTopic", () =>
|
||||
{
|
||||
var contextId = context.Items["topicID"] as string;
|
||||
if (contextId != null)
|
||||
{
|
||||
int topicId;
|
||||
if (int.TryParse(contextId, out topicId))
|
||||
return QueryById(topicId);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
var topic = (ReadOnlyTopic)cache.GetCacheItem(typeof(TopicService) + "-CurrentTopic", () =>
|
||||
{
|
||||
var contextId = context.Items["topicID"] as string;
|
||||
if (contextId != null)
|
||||
{
|
||||
int topicId;
|
||||
if (int.TryParse(contextId, out topicId))
|
||||
return QueryById(topicId);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
topic.MemberData = memberData;
|
||||
return topic;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user