Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | 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
  #71 (permalink)  
Old September 18th, 2007, 06:00 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Quote:
quote:Originally posted by Maxxim
 
Quote:
quote:looking fwd to seeing a more 'clever' and efficient way to do this, as it'd be a nice way to work with sub-sets of data. can you think of a good way to extend this in such a way??


Hello jimi!
I think your code is well!

If you have 6 categories, you call "BLL.Forums.Forum.GetForums();" six times, but only do a connection to db the first time because the last five times you gonna catch this list(allforums) from cache!!

I think it's enough!
At the mean time I need to (read the book)/(view the code) about the rest part of the forums stuff...
I need to see how the cache system works everytime a user see one post (because viewcount increment +1). But this is outside of "categories/Foruns" page!

By curiosity, how much time do you have for your "CacheDuration" ?
i set the cacheduration to the default of 600 seconds. also, i update the actual object when calcualting the postcount. so, rather than having the cache purged on the IncrementViewCount (in Post.cs), i update post.ViewCount++; in the ShowThread.aspx.cs code. this means that altho' the database is actually updated, the threadlist isn't requeried but the post object reflects each new 'view'.

[edit] just thinking out loud now. it might be a 'good' idea to have a mod function running over the object (post) ViewCount value and only update (database) every n-views, whilst still maintaning the value in the object itslef. this way the database access would be kept to abare minimum and if all went wrong (i.e. server crashed), then only n-number of views would be missed (i.e. if the mod value was 10, then only a maximum of 10 viewcount increments would be lost in any system crash). on a heavily trafficed site, this would ease the load enormously. in fact, i'd be tempted to set the mod value to anywhere between 15 and 25.
jimi

http://www.originaltalent.com
  #72 (permalink)  
Old September 18th, 2007, 10:07 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

max,

one more thing. definately check out this article (you donwload a zip with a pdf and sample code from the bottom of the abstract). it really really explains generics (and in particular, tree structures as part of collection classes) very well indeed!!

http://coders-lab.dnn-portal.com/Def...px?tabid=16942

jimi

http://www.originaltalent.com
  #73 (permalink)  
Old September 18th, 2007, 04:32 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll read this article as soon as possible!

Thanks jimi!

  #74 (permalink)  
Old September 19th, 2007, 11:18 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Max,

getting into delegates a bit, so changed the category forum stuff to the following (first is the old revised code, followed by the new implementation:

     public static List<Forum> GetForums(int CategoryID)
     {
         List<Forum> forums = null;
         string key = "Forums_Forums_" + CategoryID.ToString();

         if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
         {
             forums = (List<Forum>)BizObject.Cache[key];
         }
         else
         {
             List<Forum> allforums = BLL.Forums.Forum.GetForums();
             forums = new List<Forum>();
             foreach (Forum forumCat in allforums)
             {
                 if (forumCat.CategoryID == CategoryID || forumCat.CategoryID==0)
                 {
                     forums.Add(forumCat);
                 }
             }
             BaseForum.CacheData(key, forums);
         }
         return forums;
     }

        public static List<Forum> GetForums(int CategoryID)
        {
            List<Forum> forums = null;
            string key = "Forums_Forums_" + CategoryID.ToString();

            if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                forums = (List<Forum>)BizObject.Cache[key];
            }
            else
            {
                List<Forum> allforums = BLL.Forums.Forum.GetForums();
                forums = allforums.FindAll(
                                    delegate(Forum forum)
                                    {
                                        return forum.CategoryID == CategoryID
                                            || forum.CategoryID == 0;
                                    });
                BaseForum.CacheData(key, forums);
            }
            return forums;
        }

saves doing a big loop to find the items -pretty neet actually.!!


jimi

http://www.originaltalent.com
  #75 (permalink)  
Old September 19th, 2007, 03:41 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jimi... You are unstoppable !! :)

I use VB.net. I think there are some incompatibility functions about "predicate" .

I will try translate your script to Vb on next week and then i tell here something!

By the way, I saw your "getForums" sql procedure and I think that you have much auxiliary tables...
But please don't waist any time thinking about that until I put here my version... for you see.

I need to end my dal and bll, for debug, in order to test my SQL script.

We only need to get (* of forums table), lastpostdate and lastpostby for each forum right?

If my script's okay i'll put here for you see, for compare with yours!

But I have another challenge for us about a process to show NewPosts and OldPosts
This compromise all the rest. I will open another topic just for that!
"Forums Extensions - New/Old Posts"




Max

  #76 (permalink)  
Old September 20th, 2007, 03:43 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

max,

i don't think vb.net supports generics, so you may not be able to use the little trick that i did above, which is a shame as this gives a lot of possibilities to create functions on the fly (JIT) which would require a lot of logic (and looping) to achieve otherwise.

i did start on the new post / old post idea a while back and got a version 0.5 working failry well. however, more pressing issues (both here and on other things) took over and i never quite finished the idea. basically, what i did was:

1. create a table called UserViewPosts

CREATE TABLE [dbo].[UserViewPosts](
    [UserID] [nvarchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [ParentPostID] [int] NOT NULL,
 CONSTRAINT [PK_UserViewPosts] PRIMARY KEY CLUSTERED
(
    [UserID] ASC,
    [ParentPostID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

2. i then amended the tbh_Forums_IncrementViewCount procedure adding @ParentPostID and @UserID paramaters.

3. when the IncrementViewCount sql is run, it also adds a row in the UserViewPosts table.

4. in tbh_Forums_GetForums, add an outer join onto the UserViewPosts table (on ParentPostID) and add a virtual column (isNew) to indicate whether the thread has had any new entires since you last read it. (i.e. if the row doesn't exist and returns a null, then the virtual column would have a value of true. if the row brings back data, then the isNew vlaue would be set to false)

5. when a new post is added or an old one amended, then delete all rows from the UserViewPosts table based on the ParentPostID of the thread.

That was as far as i got. the caveats of this approach being that the cacheing would have to be re-thought to accomodate the user by user 'view' on the forum/thread list. this is why i say i'd got to version 0.5 as this is quite a big area in itself. however, i think a 'generic' discrete user session/cache 'addition' might be quite useful for other things that need to view global data but apply user additions over the top of it.

let me know what you think of the general approach that i had taken.

jimi

http://www.originaltalent.com
  #77 (permalink)  
Old September 20th, 2007, 04:11 PM
jminatel's Avatar
Wrox Staff
Points: 18,940, Level: 59
Points: 18,940, Level: 59 Points: 18,940, Level: 59 Points: 18,940, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,945
Thanks: 73
Thanked 139 Times in 101 Posts
Default

Just a minor point from me: yes, VB 2005 does support generics. If you haven't seen it, Wrox has "the" book on generics and it includes code in both VB and C#:
Professional .NET 2.0 Generics
http://www.wrox.com/WileyCDA/WroxTit...764559885.html
It's not a well known book because it is so specialized and advanced but everyone I know who has read it has told me how great it is.

Jim Minatel
Acquisitions Director
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
  #78 (permalink)  
Old September 20th, 2007, 05:27 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jimi, i written a response for your last post in "new/old Posts". I think it's better having some organization. Here, we'll discuss categories, sub-forums, and some future issues will be open in dedicate posts!
Like:
Forums Extensions - PrivateMessages
Forums Extensions - Polls
Forums Extensions - ...

Jminatel:
Hello,
of course VB supports generics. Jimibit was forgotten that i have(thanks to you) TBH working under VB.NET 2005.
BLL and DAL need the "Imports system.colletions.generic" to work with the lists! So... VB have to support generics!

The only thing VB doesn't support (as far as I know) is "anonymous delegates"

When i'll have some time, i'll try to transcode jimi Script in order to test it!
(i'm close... I just need to finish my insert/update categories/forums/subforums admin pages.)

BTW, jminatel, give us your opinion about "new/old Posts" that me and jimi are discussing!
What do you prefer?
Make all this under SQL, or work with session Variables ?


  #79 (permalink)  
Old September 22nd, 2007, 05:44 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

        public static List<Forum> GetForums(int CategoryID)
        {
            List<Forum> forums = null;
            string key = "Forums_Forums_" + CategoryID.ToString();

            if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                forums = (List<Forum>)BizObject.Cache[key];
            }
            else
            {
                List<Forum> allforums = BLL.Forums.Forum.GetForums();
                forums = allforums.FindAll(
                                    delegate(Forum forum)
                                    {
                                        return forum.CategoryID == CategoryID
                                            || forum.CategoryID == 0;
                                    });
                BaseForum.CacheData(key, forums);
            }
            return forums;
        }
I confirm... VB don't support this!
I need to make "for each" method and then add this items to list<forum>

However this isn't much different... In your anonymous delegate, the system will search the category item by item!

  #80 (permalink)  
Old September 23rd, 2007, 03:18 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Max,

Main difference is performance (it's been measured on one of the sites that i'll dig the reference out for). the FindAll (and ForEach) associated with list <T> in c# are 50% (in some cases) faster than the foreach() loop structure.

mind you, for the small amounts of data that we're searching thro (usually sql subsets, then it's probably not an issue).

anyway - will keep you abreast of any further things that i find.


jimi

http://www.originaltalent.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
AJAX Extensions ilegend .NET Framework 3.5 1 September 19th, 2008 03:32 AM
Some Extensions plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 29th, 2008 11:57 AM
PHP Extensions Dnigma Pro PHP 0 June 22nd, 2006 12:41 AM
File Extensions nbnelson C# 2 August 25th, 2003 12:09 PM
converting Forum.aspx to Forum.ascx (help) drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 11th, 2003 12:27 PM



All times are GMT -4. The time now is 12:32 AM.


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