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?
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.
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.