Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2007, 08:38 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default Membership vs custom ForumMembers

I don't know if I understand membership well…
I want to make a site based on thebeerhouse.
In that forum each time that I open one topic page, the system has to show for each reply:

author.profile.posts
author.profile.avatar
author.profile.mail
author.profile.msn
author.profile.signature
author.profile. (etc)

If the topics page has 20 replies all by different members(authors)
There will be 20 members + 1 dataset for 20 topics messages.

This is 21 database connections for one single page!

Give a look in the code:

Code:
<asp:GridView ID="gvwPosts" runat="server" SkinID="Posts" AllowPaging="True" AutoGenerateColumns="False" ShowHeader="false"
      DataSourceID="objPosts" PageSize="25" DataKeyNames="ID" OnRowCommand="gvwPosts_RowCommand" OnRowDataBound="gvwPosts_RowDataBound">
      <Columns>
         <asp:TemplateField ItemStyle-Width="120px" ItemStyle-CssClass="postinfo">
            <ItemTemplate>
               <div class="posttitle" style="text-align:right;">
                  <asp:HyperLink runat="server" ID="lnkEditPost" ImageUrl="~/Images/Edit.gif" NavigateUrl="~/AddEditPost.aspx?ForumID={0}&ThreadID={1}&PostID={2}" />&nbsp;
                  <asp:ImageButton runat="server" ID="btnDeletePost" ImageUrl="~/Images/Delete.gif" 
                     OnClientClick="if (confirm('Are you sure you want to delete this {0}?') == false) return false;"/>&nbsp;&nbsp;
               </div>
               <asp:Literal ID="lblAddedDate" runat="server" Text='<%# Eval("AddedDate", "{0:D}<br/><br/>{0:T}") %>' />

               <asp:Literal ID="lblAddedBy" runat="server" Text='<%# Eval("AddedBy") %>' /><br /><br />
               <asp:Literal ID="lblPosts" runat="server" 
                  Text='<%# "Posts: " + GetUserProfile(Eval("AddedBy")).Forum.Posts.ToString() %>' />
               <asp:Literal ID="lblPosterDescription" runat="server" 
                  Text='<%# "<br />" + GetPosterDescription(GetUserProfile(Eval("AddedBy")).Forum.Posts) %>' 
                  Visible='<%# GetUserProfile(Eval("AddedBy")).Forum.Posts >= Globals.Settings.Forums.BronzePosterPosts %>'/>                  <br /><br />
               <asp:Panel runat="server" ID="panAvatar" Visible='<%# GetUserProfile(Eval("AddedBy")).Forum.AvatarUrl.Length > 0 %>'>
                  <asp:Image runat="server" ID="imgAvatar" ImageUrl='<%# GetUserProfile(Eval("AddedBy")).Forum.AvatarUrl %>' />
                  <br /><br />
               </asp:Panel>               
            </ItemTemplate>
         </asp:TemplateField>       
         <asp:TemplateField>
            <ItemTemplate>
               <div class="posttitle"><asp:Literal ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' /></div>
               <div class="postbody">
                  <asp:Literal ID="lblBody" runat="server" Text='<%# Eval("Body") %>' /><br /><br />
                  <asp:Literal ID="lblSignature" runat="server" 
                     Text='<%# Helpers.ConvertToHtml(GetUserProfile(Eval("AddedBy")).Forum.Signature) %>' /><br /><br />
                  <div style="text-align: right;">
                     <asp:HyperLink runat="server" ID="lnkQuotePost" 
                        NavigateUrl="~/AddEditPost.aspx?ForumID={0}&ThreadID={1}&QuotePostID={2}">Quote Post</asp:HyperLink>
                  </div>
               </div>
            </ItemTemplate>
         </asp:TemplateField>       
      </Columns>      
   </asp:GridView>


Code-Behind:

Code:
      protected ProfileCommon GetUserProfile(object userName)
      {
         string name = (string)userName;
         if (!profiles.Contains(name))
         {
            ProfileCommon profile = this.Profile.GetProfile(name);
            profiles.Add(name, profile);
            return profile;
         }
         else
            return profiles[userName] as ProfileCommon;
      }
If my replies page has 20 replies by different members i have 21 database connections right?
It is good policy?

Thanks very much.
I want to upgrade my forum for framework 2 and i need to resolve this doubts... I only want a fast page.

p.s. I tried to make this discussion in problem/solution(2) forum but I didn't have much success...
 
Old July 27th, 2007, 09:10 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No discussion?

 
Old July 28th, 2007, 03:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think you're observations are correct. If you load a thread for the first time with 20 different participants, you have at least 21 database calls.

However, I don't think this is a problem in the real world. First of all, you probably won't have that many different participants in a single thread. Obviously, your mileage may vary as it depends on the forum you are building.

But what's more important, the code seems to cache the ProfileCommon objects:
Code:
string name = (string)userName;
if (!profiles.Contains(name))
{
  ProfileCommon profile = this.Profile.GetProfile(name);
  profiles.Add(name, profile);
  return profile;
}
else
  return profiles[userName] as ProfileCommon;
  I don't know the scope of the profiles variable, but it seems to cache at least the profiles for the current request. So, if you have the same participants in a thread, it loads the user details only the first time they are needed. You could extend this and cache the details across multiple threads / posts if that's not already the case.

HtH,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 28th, 2007, 02:47 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar!

It was necessarily this that I wanted to know.
What can I do in order to know if this cache only functions for one request or for several requests.
Some ideia ?

Thanks one more time!

 
Old July 28th, 2007, 04:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Just look at the code that declares the profiles variable. If it's a privately scoped field, it works for the current request only. If it's a property that uses the Cache as it's backing store, it's using the cache....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Membership Provider Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 1st, 2008 05:16 PM
Custom Membership Provider kulkarnimonica ASP.NET 2.0 Professional 0 June 21st, 2007 03:56 PM
problem with custom membership provider hertendreef ASP.NET 2.0 Professional 8 April 17th, 2007 12:11 PM
Issue with custom membership provider cacaldo ASP.NET 2.0 Professional 1 October 7th, 2006 03:05 AM
custom membership provider msrnivas General .NET 1 September 18th, 2005 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.