Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 11th, 2007, 11:13 AM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default Forums GetUserProfile

I'm Confused about this application

I'm reading the book, exploring the application and make my own application.

When thebeerhouse show a thread page (with all the posts defined in webconfig pge by "topicsbypage") I see that the code for every post is

GetUserProfile(Eval("AddedBy")).Forum.Posts
Posts: " & GetUserProfile(Eval("AddedBy")).Forum.Posts.ToStri ng()
GetUserProfile(Eval("AddedBy")).Forum.AvatarUrl
GetPosterDescription(GetUserProfile(Eval("AddedBy" )).Forum.Posts

This are four connections ??
I mean... Every time I have GetUserProfile(UserName) I have to make a connection to DB ?

Because If I have 10 posts in one page I have to make 10x4 + 1 connections!!

I'm confused because I can't acess the "getUserProfile" in order to know if all usersprofile are saved in cache or... a connetion to DB is made everytime that is need get something for "getUserProfile"

Please, anyone that understand my point tell me if i'm right

(because if i am, I need to remove the "posts, avatar etc from the binary field in profile and put it in another table to facilitate sql code and retrieve all that using one single connection!)

Thanks!
  #2 (permalink)  
Old July 12th, 2007, 05:42 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Max,

in the ShowThread.aspx.cs page, you have the following:

        // Retrieves and returns the profile of the specified user. The profile is cached once
        // retrieved for the first time, so that it is reused if the profile for the same user
        // will be requested more times on the same request
        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;
        }

The profile is retrieved the 1st time around and then taken from the Hashtable profiles = new Hashtable() each subsequent time (keyed on userName).

Hope i haven't misunderstood :)

[edit] of course, this is only at 'page level', so every call to a new thread page will retrieve each profile the 1st time and then reuse it for the remainder of the calls. i guess it's a trade of against putting the profiles in cache at the expense of knocking out more 'expensive' data. the way it stands, if there were 5 contributors to a thread, then the profile would be called 5 times from the database BUT then retrieved from the profiles (Hashtable()) object for each property required from it.

jimi

http://www.jamestollan.com
  #3 (permalink)  
Old July 12th, 2007, 08:18 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: , , .
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to vantoko
Default

Hi Jimi,

I don't think you misunderstood.
On the other hand, it would be better to have a userprofile object filled in and reuse that one.

Koen

  #4 (permalink)  
Old July 12th, 2007, 08:47 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Koen,

yes, the only issue that i can see is that you'd have to put the Hashtable object into the HttpContext.Current.Cache(). i'm just not that sure as to whether the loading of that on a global basis would become quite heavy. of course, you could have a very long expiration on that (making it 'almost' persistant) which would mean that it was always in cache.

here's a quick 'n' dirty update on the function which places the hashtable into the cache for global use:

protected ProfileCommon GetUserProfile(object userName)
        {
            string name = (string)userName;

            // this would be stored as a constant for use in profile updates etc...
            string cacheKey = "profileCache";

            if (HttpContext.Current.Cache[cacheKey] == null)
            {
                // cache it for 24 hours - though, profile could change
                // within this space of time. perhaps we could also update
                // the same cache object when a profile is updated
                HttpContext.Current.Cache.Add(cacheKey, profiles, null,
                     DateTime.MaxValue, new TimeSpan(24, 0, 0),
                     CacheItemPriority.AboveNormal, null);
            }
            else
                profiles = (Hashtable)HttpContext.Current.Cache.Get(cacheKey) ;
            if (!profiles.Contains(name))
            {
                ProfileCommon profile = this.Profile.GetProfile(name);
                profiles.Add(name, profile);
                return profile;
            }
            else
                return profiles[userName] as ProfileCommon;
        }

the directive using System.Web.Caching; also will need to be added at the top of the page.

might be a smart way fwd, not sure. i'll let the reader decide ;)

[edit] i'm assuming that asp.net doesn't by default keep a background cache of profiles as they are selected. i'm assuming this due to the fact that MB goes to the length of creating a hashtable in the 1st place!!. also, perhaps this cache logic should be placed in the BLL - not sure. but for now, this looks like a good way fwd

jimi

http://www.jamestollan.com
  #5 (permalink)  
Old July 12th, 2007, 12:52 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by jimibt
            if (!profiles.Contains(name))
            {
                ProfileCommon profile = this.Profile.GetProfile(name);
                profiles.Add(name, profile);
                return profile;
            }
            else
                return profiles[userName] as ProfileCommon;
        }
Thanks for your question jimibt!

By this method, If you open a thread page with 20 posts all from different users you'll need to make 20 connections to DB, right?

If you have one table in sql, like [tbh_forumMembers] with:

Posts, WebSite, RankID, etc.

you could fill your dataset with the 20 posts and profile fields by post!

By "sql" method you could show in every row the:
post.message,
post.memberpost,
post.memberrankid,
post.memberEMail,
post membershowemail[true or false],
post.memberMsn,
post.MemberYhm,
post.MemberAvatar
(etc)

I think that if all this came from one single dataset it would be more quickly...

But if you store all profile information in cache, if you have a forum with 2000 users... i think it would be an expensive way (in terms of data) to do this (remember that only 35%(+/-) of members participate on forums...)

I start this question because I probably don't understand quite well the profile method!

I just want to have a fast website, with thousands of members and millions of posts...

I'm starting a new application based on this book and I have doubts If this method is the better...

Maybe the first priority of this book is teaching some membership stuff with aspnet precompiled code for small-mid sites.

I will appreciate your opinion!

Forgive my bad english!
Max

  #6 (permalink)  
Old September 14th, 2007, 06:31 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm working on this forum from past 2 hours and already found a several bug!

When administrator delete a topic or reply, TBH don't update the NumPosts of this member in binary Profile!

This is hard... because if admin delete a topic, sql delete all post replies by cascade delete! So... if we want update NumPost from sql to asp.net membership we have to make some routine to check all posts count by each member and then update one by one on asp.net membership!

That's it! I don't want to think about it anymore!
I will make a memberForumSettings table with all Forum Information...
Msn, YHM, Email, NumPosts, ForumLastVisit, etc...

By this way I can retrieve one topic page by a single sql connection, with easy update/deletes, and check new posts since last visit by "ForumLastVisit"

I have the disadvantage of having one more table, procedures and bll/dal code but it traduce a more efficient result!

Marco wanted to have a simple forum with membership recurse! But this isn't the best way!

BTW if anyone wants to retify the code change the "dbo.tbh_Forums_DeletePost" procedure.
After delete posts... search the topic and update "lastPostDate" and "lastPostby..."

Marco missed that!

  #7 (permalink)  
Old September 16th, 2007, 10:38 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hmm. Not sure if I agree with you, Maxxim. I haven't yet reached the chapter, but I can understand the general gist.

However, the way I want to do things for my site is that even if a thread is marked for deletion, it will not really be deleted. Instead, I will set an active flag for the site to 0, meaning my users will never see it again. It will just not be removed from the database, and thus, any posts a user made will still be there, and thus the postcount would be correct.

Unless you have some sort of stalker, or a very new forum poster, I doubt you'd have any users seriously noticing that a certain user made a post that dissappeared.

Like you said though, if you want things to all add up, you would have to implement the logic in the deletion stored procedure. I wouldn't update all possible postcounts of all users after a delete, just implement a AFTER DELETE trigger, use the DELETED table to find the posts in the removed thread and do a DISTINCT UserID, COUNT(1) with a GROUP BY UserID to figure out the amount of posts made by a user in the thread. Then just substract those numbers from their NumPosts.

http://entropia-online.blogspot.com/
  #8 (permalink)  
Old September 16th, 2007, 12:05 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Viagra, you are forgetting that "their NumPosts" are saved into a single binary field with a lots of profile stuff!
You can't just update this "NumPosts" under sql_procedures!

I have an auxiliar table with the name "DeletedPosts". Every time i(or any moderator) delete a post/topic, my system move all the deleted items to that table.

I have 20 moderators that sometimes need to delete posts. And later i want to see what posts they deleted!

In past 6 months, i deleted a few abusive posts from some members...

  #9 (permalink)  
Old September 16th, 2007, 12:15 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For doing on your way, you need to retrieve a list(or table) with "Username, NumPosts" from a sql(it is easy) to asp.net.
Then you need to do a routine with:

list all members
 For each member
  update NumPosts from list retrieved from sql
 end for

It isn't hard... Everything is possible, but, i think that isn't the best way...

If you delete 20 posts for day (i delete on my forum) and if you have 10.000 users on your site, you are retrieving at least 20x1 list with 10.000 items from your database to your asp.net application!

It can traduce in a slower application at this moment and a huge asp-sql traffic.

So... in my opinion it's better to have a single column anywhere on sql with a (int) column = "NumPosts"


  #10 (permalink)  
Old September 16th, 2007, 12:24 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Maxxim,

I indeed was under the impression there was a single column option. The technique I described though uses the DELETED table of SQL Server. If you have a stored procedure that deletes data, right after the delete, the trigger would be called, and the DELETED table would contain only the rows that got deleted (including the userID of the person posting).

It would be very efficient to do your work on that subset of relevant data, rather than any other way. You really would only be updating the profiles of those members who posted in the deleted thread (or post).

http://entropia-online.blogspot.com/
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Breaking the Forums? iPagan BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 August 2nd, 2007 02:02 PM
help on forums dennisssss BOOK: ASP.NET Website Programming Problem-Design-Solution 1 February 4th, 2007 03:15 AM
Forums Help jsantamaria BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 August 28th, 2006 10:57 PM
more forums? MiltonBC Forum and Wrox.com Feedback 5 November 12th, 2004 03:15 PM



All times are GMT -4. The time now is 07:02 PM.


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