Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsBlogBlogBlog Archive bug and Performance Problem. Code to fix thatBlog Archive bug and Performance Problem. Code to fix that
Previous
 
Next
New Post
1/28/2007 4:45 PM
 

I tested this with DNN 4.4.0, and VS2005:

When preparing future posts I see that DNN calendar module shows posts that there are not even published... While taking a look at the code I saw this (archive.ascx.vb Line 73):

calMonth.SelectedDates.Clear()

 

objBlog = objCtlBlog.GetBlog(objArchiveDay.BlogID)

 

 

calMonth.SelectedDates.Add(dDate)

 

In the code we see that it does not check if the entry is published or not, and seems it makes a db call for each day in the month in which there is a post, so for a "daily populated blog" you can have as much queries to the db as days in the month...  Even worse, when examining the results of Blog_GetBlogDaysForMonth stored procedure (it returns a row for each blog entry) you can see that it makes a database call for each blog entry in the month, so if you have more than one post in a day, you make more than a query in that day. I wonder how many queries would be made for a month in www.dotnetnuke.com... A simple hashtable with the blog data and checking the published days would have made the job...

I wanna reduce the number of queries and showing only the days in which I have published posts, so I'll change the query to return if the entry has been published or not and the blog data I need for that, the changed stored proc looks like this:

ALTER

PROCEDURE [dbo].[Blog_GetBlogDaysForMonth]

(

@PortalID int, @BlogID int, @BlogDate DateTime )

AS

DECLARE

SELECT

@BlogMonth int
DECLARE
@BlogYear int @BlogMonth = DATEPART(mm, @BlogDate)
SELECT @BlogYear = DATEPART(yy, @BlogDate)

If

@BlogID > -1

BEGIN

ELSE

BEGIN

 

 

 

 

 

 

SELECT E.[EntryID], E.[BlogID], B.[ParentBlogID], E.[Title],
E.[Published],E.[AddedDate],U.[Username],B.[UserID],
DATEPART(mm, E.AddedDate) as AddedMonth,
DATEPART(yy, E.AddedDate) as AddedYear,
B.[Culture], B.[DateFormat], B.[TimeZone]FROM dbo.Blog_Blogs B INNER JOIN
dbo.Blog_Entries E ON B.[BlogID] = E.[BlogID] INNER JOIN
dbo.Users U ON B.[UserID] = U.[UserID]WHERE B.[PortalID] = @PortalID AND
(B.[BlogID] = @BlogID OR B.[ParentBlogID] = @BlogID) AND
DATEPART(yy, E.AddedDate) = @BlogYear AND
DATEPART(mm, E.AddedDate) = @BlogMonthORDER BY E.AddedDate

END

 

 

 

 

 

 

SELECT E.[EntryID],E.[BlogID], B.[ParentBlogID], E.[Title],
E.[Published], E.[AddedDate],U.[Username], B.[UserID],
DATEPART(mm, E.AddedDate) as AddedMonth,
DATEPART(yy, E.AddedDate) as AddedYear,
B.[Culture], B.[DateFormat], B.[TimeZone]FROM dbo.Blog_Blogs B INNER JOIN
dbo.Blog_Entries E ON B.[BlogID] = E.[BlogID] INNER JOIN
dbo.Users U ON B.[UserID] = U.[UserID]WHERE B.[PortalID] = @PortalID AND
DATEPART(yy, E.AddedDate) = @BlogYear AND
DATEPART(mm, E.AddedDate) = @BlogMonthORDER BY E.AddedDate

END

The data for this query is stored in objects of the ArchiveDays class, so I will modify the class with the new attibutes, the final code is this (The file is blogInfo.vb):

#Region "Class ArchiveDays"

    Public Class ArchiveDays

 

#Region "local property declarations"

        Dim _BlogID As Integer

        Dim _EntryID As Integer

        Dim _AddedDate As DateTime

        Dim _Title As String

        Dim _userName As String

        Dim _userID As Integer

        Dim _published As Boolean

        Dim _culture As String

        Dim _dateFormat As String

        Dim _timeZone As Integer

#End Region

 

#Region "Constructors"

        Public Sub New()

        End Sub

 

        Public Sub New(ByVal BlogID As Integer, ByVal EntryID As Integer, ByVal AddedDate As DateTime, _

            ByVal Title As String, ByVal UserName As String, ByVal UserID As Integer, ByVal Published As Boolean, ByVal Culture As String, _

            ByVal DateFormat As String, ByVal TimeZone As Integer)

            Me.BlogID = BlogID

            Me.EntryID = EntryID

            Me.AddedDate = AddedDate

            Me.Title = Title

            Me.UserName = UserName

            Me.UserID = UserID

            Me.Published = Published

            Me.Culture = Culture

            Me.DateFormat = DateFormat

            Me.TimeZone = TimeZone

        End Sub

#End Region

 

#Region "Public Properties"

        Public Property BlogID() As Integer

            Get

                Return _BlogID

            End Get

            Set(ByVal Value As Integer)

                _BlogID = Value

            End Set

        End Property

 

        Public Property EntryID() As Integer

            Get

                Return _EntryID

            End Get

            Set(ByVal Value As Integer)

                _EntryID = Value

            End Set

        End Property

 

        Public Property AddedDate() As DateTime

            Get

                Return _AddedDate

            End Get

            Set(ByVal Value As DateTime)

                _AddedDate = Value

            End Set

        End Property

 

        Public Property Title() As String

            Get

                Return _Title

            End Get

            Set(ByVal Value As String)

                _Title = Value

            End Set

        End Property

 

        Public Property UserName() As String

            Get

                Return _userName

            End Get

            Set(ByVal Value As String)

                _userName = Value

            End Set

        End Property

 

        Public Property UserID() As Integer

            Get

                Return _userID

            End Get

            Set(ByVal value As Integer)

                _userID = value

            End Set

        End Property

 

        Public ReadOnly Property AddedDay() As Integer

            Get

                Return _AddedDate.Day

            End Get

        End Property

 

        Public ReadOnly Property AddedMonth() As Integer

            Get

                Return _AddedDate.Month

            End Get

        End Property

 

        Public ReadOnly Property AddedYear() As Integer

            Get

                Return _AddedDate.Year

            End Get

        End Property

 

        Public Property Published() As Boolean

            Get

                Return _published

            End Get

            Set(ByVal value As Boolean)

                _published = value

            End Set

        End Property

 

        Public Property Culture() As String

            Get

                Return _culture

            End Get

            Set(ByVal value As String)

                _culture = value

            End Set

        End Property

 

        Public Property DateFormat() As String

            Get

                Return _dateFormat

            End Get

            Set(ByVal value As String)

                _dateFormat = value

            End Set

        End Property

 

 

        Public Property TimeZone() As Integer

            Get

                Return _timeZone

            End Get

            Set(ByVal value As Integer)

                _timeZone = value

            End Set

        End Property

#End Region

 

    End Class

#End Region

#Region "Class ArchiveDays"

    Public Class ArchiveDays

 

#Region "local property declarations"

        Dim _BlogID As Integer

        Dim _EntryID As Integer

        Dim _AddedDate As DateTime

        Dim _Title As String

        Dim _userName As String

        Dim _userID As Integer

        Dim _published As Boolean

        Dim _culture As String

        Dim _dateFormat As String

        Dim _timeZone As Integer

#End Region

 

#Region "Constructors"

        Public Sub New()

        End Sub

 

        Public Sub New(ByVal BlogID As Integer, ByVal EntryID As Integer, ByVal AddedDate As DateTime, _

            ByVal Title As String, ByVal UserName As String, ByVal UserID As String, _

            ByVal Published As Boolean, ByVal Culture As String, _

            ByVal DateFormat As String, ByVal TimeZone As Integer)

            Me.BlogID = BlogID

            Me.EntryID = EntryID

            Me.AddedDate = AddedDate

            Me.Title = Title

            Me.UserName = UserName

            Me.Published = Published

            Me.Culture = Culture

            Me.DateFormat = DateFormat

            Me.TimeZone = TimeZone

        End Sub

#End Region

 

#Region "Public Properties"

        Public Property BlogID() As Integer

            Get

                Return _BlogID

            End Get

            Set(ByVal Value As Integer)

                _BlogID = Value

            End Set

        End Property

 

        Public Property EntryID() As Integer

            Get

                Return _EntryID

            End Get

            Set(ByVal Value As Integer)

                _EntryID = Value

            End Set

        End Property

 

        Public Property AddedDate() As DateTime

            Get

                Return _AddedDate

            End Get

            Set(ByVal Value As DateTime)

                _AddedDate = Value

            End Set

        End Property

 

        Public Property Title() As String

            Get

                Return _Title

            End Get

            Set(ByVal Value As String)

                _Title = Value

            End Set

        End Property

 

        Public Property UserName() As String

            Get

                Return _userName

            End Get

            Set(ByVal Value As String)

                _userName = Value

            End Set

        End Property

 

        Public Property UserID() As Integer

            Get

                Return _userID

            End Get

            Set(ByVal value As Integer)

                _userID = value

            End Set

        End Property

 

        Public ReadOnly Property AddedDay() As Integer

            Get

                Return _AddedDate.Day

            End Get

        End Property

 

        Public ReadOnly Property AddedMonth() As Integer

            Get

                Return _AddedDate.Month

            End Get

        End Property

 

        Public ReadOnly Property AddedYear() As Integer

            Get

                Return _AddedDate.Year

            End Get

        End Property

 

        Public Property Published() As Boolean

            Get

                Return _published

            End Get

            Set(ByVal value As Boolean)

                _published = value

            End Set

        End Property

 

        Public Property Culture() As String

            Get

                Return _culture

            End Get

            Set(ByVal value As String)

                _culture = value

            End Set

        End Property

 

        Public Property DateFormat() As String

            Get

                Return _dateFormat

            End Get

            Set(ByVal value As String)

                _dateFormat = value

            End Set

        End Property

 

 

        Public Property TimeZone() As Integer

            Get

                Return _timeZone

            End Get

            Set(ByVal value As Integer)

                _timeZone = value

            End Set

        End Property

#End Region

 

    End Class

#End Region

Then I have to change the loop to check if the entry is published or not, and in case the user is admin (or whatever, I know little about dnn security model), mark the day or not. I copied the check from viewEntry.ascx.vb. Note that I will only check the permissions when the entry is not published, So the loop in Archive.ascx.vb Line 73 would be:

 

 

For Each objArchiveDay In objArchiveDays'If it's published or the current user has the proper permissions... Mark the day

 

If (objArchiveDay.Published OrElse Utility.HasBlogPermission(Me.UserId, objArchiveDay.UserID, ModuleId)) Then

 

 

calMonth.SelectedDates.Add(dDate)

 

Dim strDate As String = Utility.FormatDate(objArchiveDay.AddedDate, objArchiveDay.Culture, objArchiveDay.DateFormat, objArchiveDay.TimeZone)Dim dDate As Date = Utility.ParseDate(strDate, objArchiveDay.Culture)End If

 

Next

The result should be that the calendar shows only the proper posts and that only the necessary database calls are made, there is no point on enhancing DNN core when a module makes n database calls to sending all the optimizations to hell.

The calendar also has the problem of the dates which are not calculated properly, I have just came across an entry located on February 1st but due to the extrange issues with timezones it is stored as being from January 31th, so it appears on the January calendar as being February the 1st and does not appear in february calendar. And there is still the problem that when the only post in a month has not been published, the month appears in the month list... I think I'll try to fix this soon.

Enrique Blanco (www.eblanco.com)

For Each objArchiveDay In objArchiveDaysDim strDate As String = Utility.FormatDate(objArchiveDay.AddedDate, objBlog.Culture, objBlog.DateFormat, objBlog.TimeZone)Dim dDate As Date = Utility.ParseDate(strDate, objBlog.Culture)Next
 
New Post
1/28/2007 7:58 PM
 

It seems that the html copy & paste has gone to hell.

The article is here: http://www.eblanco.com/Default.aspx?tabid=36&EntryID=91

Enrique Blanco (www.eblanco.com)

 

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsBlogBlogBlog Archive bug and Performance Problem. Code to fix thatBlog Archive bug and Performance Problem. Code to fix that


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out