Welcome Guest! To enable all features please Login or Register.
Options
View
Go to last post Go to first unread
Offline Zero2Cool  
#1 Posted : Wednesday, March 30, 2016 1:19:02 PM(UTC)
Zero2Cool


Rank: YAF Leader

Reputation:

Medals: Medal of Honor for the Support Knight: Given to a community member who has assisted lots and lots of people!

Joined: 4/26/2011(UTC)
Posts: 1,062
Man
United States
Location: in a van down by the river

Thanks: 234 times
Was thanked: 101 time(s) in 92 post(s)
The YAF software allows us to set a Status for a topic. The default options are something like Informative, Solved, etc.

I wanted to be able to showcase specifically designated Topics on their own separate page, like you see here http://www.packershome.com/Blog

I created the Status called "Blog".

And use this stored procedure to retrieve the fields I wanted. I put this in a userControl and depending on where in my site I embed the control I want to show the top X amount vs the top Y amount so that is why the @Top parameter is there.

Code:
[ph_blog_select] (@Top int) 
AS
BEGIN

DECLARE @Topper INT = @Top

   SELECT TOP (@Topper) (SELECT COUNT(M.TopicID)
FROM yaf_Message M WHERE T.TopicID = M.TopicID ) as Total, 
   T.TopicID, U.Name, T.Posted, T.Topic, M.Message, T.LastMessageID
   FROM yaf_Topic as T 
   LEFT JOIN yaf_Message as M 
   ON T.TopicID = M.TopicID 
   LEFT JOIN yaf_User as U 
   ON U.UserID = T.UserID 
   WHERE T.Status = 'Blog' 
   AND M.Position = 0 
   AND T.LastMessageFlags = 22
   ORDER BY T.Posted DESC
    
END

Edited by user Thursday, March 31, 2016 5:49:58 AM(UTC)  | Reason: Not specified

Sponsor
Offline Ordinary Nimda  
#2 Posted : Sunday, April 10, 2016 2:17:32 PM(UTC)
Ordinary Nimda


Rank: YAF Lover

Reputation:

Joined: 2/8/2016(UTC)
Posts: 34
Slovenia
Location: LJ

Thanks: 13 times
Was thanked: 2 time(s) in 2 post(s)
This is in fact a very good idea - plus it looks cool on your Packers forum. You did a really great job there. It shows how neatly YAF can be customized.

Note:
My experience says, that on high volume web sites, such quick-link lists must be cached, because they generate additional SQL queries, which are expensive time-wise, especially if the SQL server instance is running on another physical machine. I usually put to cache actual XML fragment-strings, so there is minimal overhead involved. Knowing when and how to purge the cache, is the hard question here... :D
Offline Zero2Cool  
#3 Posted : Monday, April 11, 2016 4:48:26 AM(UTC)
Zero2Cool


Rank: YAF Leader

Reputation:

Medals: Medal of Honor for the Support Knight: Given to a community member who has assisted lots and lots of people!

Joined: 4/26/2011(UTC)
Posts: 1,062
Man
United States
Location: in a van down by the river

Thanks: 234 times
Was thanked: 101 time(s) in 92 post(s)
Originally Posted by: Ordinary Nimda Go to Quoted Post
This is in fact a very good idea - plus it looks cool on your Packers forum. You did a really great job there. It shows how neatly YAF can be customized.

Note:
My experience says, that on high volume web sites, such quick-link lists must be cached, because they generate additional SQL queries, which are expensive time-wise, especially if the SQL server instance is running on another physical machine. I usually put to cache actual XML fragment-strings, so there is minimal overhead involved. Knowing when and how to purge the cache, is the hard question here... :D


Can you further explain what you're talking about in regards to caching XML? I've stored the class object collection in cache before, but no experience using XML for it.
Offline Ordinary Nimda  
#4 Posted : Monday, April 11, 2016 5:42:00 AM(UTC)
Ordinary Nimda


Rank: YAF Lover

Reputation:

Joined: 2/8/2016(UTC)
Posts: 34
Slovenia
Location: LJ

Thanks: 13 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: Zero2Cool Go to Quoted Post


Can you further explain what you're talking about in regards to caching XML? I've stored the class object collection in cache before, but no experience using XML for it.


Any object you make, is in essence just an injection of a string (XML or HTML formatted) into the output flow. Caching .NET objects might not be a good idea, as there can be threading issues. So you first generate the object (your recordset in this instance), then you walk the recordset and generate XML or HTML fragment output, the way it would actually appear in the resulting HTML. This fragment is what you put to cache, this object is in reality just a .NET String - which is guaranteed to be thread-safe in .NET.

PSEUDO CODE for usage, using the standard .NET Application Cache functionality and the .NET web Application Locking mechanism.
Code:

// pseudo code, this is the essence, I will not add the details and correct syntax, but the code is actually not larger that this.
String my_fragment = "";   // this is the return value XML or HTML formatted output from your C# object;
Application .Lock ();          // HTTP Application object
// "my_XML_fragment" is the name of the cached String object
if (cache ("my_XML_fragment")  != null) // pseudo code: check syntax and useage
{
    // directly from .NET object cache, this is the XML or HTML output from your object
    my_fragment = cache ("my_XML_fragment");  // this is always a String
    // you should immediately Unlock the Application here, then return the string
}
else
{
   // After startup or after the cache is purged, this will be done at the first next web request
   // use a StringBuilder object to generate the whole properly formatted XML or HTML fragment as it would appear in the output  
   String SQL_result_string = Generate_SQL_query (); // your query + walking the recordset to generate XML or HTML formatted output string
   // save it to cache
   cache ("my_XML_fragment") = SQL_result_string;  // this is a String
   // now also in cache, this is XML or HTML output from your object
   my_fragment = cache ("my_XML_fragment");   // this is always a String
}
Application.Unlock ();  // HTTP Application object, if I remember correctly
return my_fragment;   // String


The rest is the same as is in your code, except for the strategy of purging the cache for this object, which is the important and hard part. I do not like time-triggered cache purging, but use cache purging like this: when a new record is inserted, deleted or edited into the database, which could influence the above SQL result, the cache is purged. There might of course be other cache fragments too, maybe 20 or more if you have a rich page... So everything is being done automatically, by itself. The overhead is never greater, than it would be if there were no caching, or only a few percent greater at most. I have done this in high volume sites even on the old ASP (using Arrays of strings) and it worked like a charm. In .NET C# it is so much more elegant and easy to implement, that there is no excuse to not using this performance enhancing functionality.

NOTE:
Keep the code inside the Lock-Unlock section as small as possible, good error checking should be done, Unlocking and then exiting quickly if errors. If there are many concurrent page requests, they will all be waiting for this section to complete when the fat portion is being generated. Of course there can be many Lock.Unlock sections, so one can do this inside any and all objects like in the example you have given.

Edited by user Monday, April 11, 2016 5:44:03 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Ordinary Nimda for this useful post.
Zero2Cool on 4/11/2016(UTC)
Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error