Strange PubliCatioNStart criterion for blog entries

Vote:
 

In default Relate templates there is this kinda strage criterion for from when a blog entry is available in listings:

// Must be published
entryQuery.PublicationStart = new DateTimeCriterion();
DateTime now = DateTime.Now;
entryQuery.PublicationStart.Value = now.Date.AddHours(now.Hour).AddMinutes((now.Minute / 10) * 10);
entryQuery.PublicationStart.Operator = ComparisonOperator.LessThan;

That makes entries show between 1-10 minutes after publication.
Anyone could tell me why this done that way? Is it to prevent something?

#63316
Nov 15, 2012 9:32
Vote:
 

In short: It builds a datetime object which is the most recent passed 10 minute interval: When now is 8.06 it will be 8.00 and at 8.53 it will be 8.50. The reason this happens is because the integer division truncates the decimal part, it does not rounc correctly (if it did, 6/10 would round up).

Why a datetime like this is used in the query is a different question. I can imagine it is to increase performance - if the query result is cached based on the parameters of the query, the same cached result will be returned for 10 minutes instead of generating a new cached set for every query if the actual DateTime.Now would be used. But that's just a guess.

#63337
Nov 15, 2012 10:48
Vote:
 

Thanks! That sounds like a reasonable explanation! If query is cached based on parameters, this makes it unique for each 10min period. So as performance is not an issue in current environment I will try changing it to 1-2 min "cache" for now.

#63356
Nov 15, 2012 19:11
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.