This is related to the 'number of times your profile is visited by others'.
How exactly does it work? For example, in my profile page, profile view count is 171.
This is related to the 'number of times your profile is visited by others'.
How exactly does it work? For example, in my profile page, profile view count is 171.
To note, I am not a Stack Exchange developer nor am I associated with them. As such, this is an unofficial response. I was just very curious and am a huge fan of the ASP.NET MVC framework. These are my findings.
I believe it is caching... it is always caching.
What is it caching? It is caching something Stack Exchange has termed QuerySets which are pretty much stored sql execution plans which match to a query, a userid, and an ip address (there are a few other params). This information is dated, I am pretty sure the code is a cached version. But really, it is from 2012ish.
public class QuerySet
{
public int Id { get; set; }
public int InitialRevisionId { get; set; }
public int CurrentRevisionId { get; set; }
public int? OwnerId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime LastActivity { get; set; }
public int Votes { get; set; }
public int Views { get; set; }
public string OwnerIp { get; set; }
// these are loaded via QueryUtil.LoadFullQuerySet
public Revision InitialRevision { get; set; }
public Revision CurrentRevision { get; set; }
public List<Revision> Revisions { get; set; }
public User Owner { get; set; }
}
The execution plans are cached in CachedResult.ExecutionPlan
by linking CachedResult.QueryHash
to QuerySet.Revision.Query.QueryHash
.
The QuerySet is created the first time a sql execution plan is created from one IP address requesting a page, otherwise the QuerySet is cached, in which case the revision is updated. The cache window is 15 minutes, and inside of this window, no new views are counted. Every time the QuerySet is fetched it will reset the window.
private const int VIEW_EXPIRES_SECS = 15*60; // view information expires in 15 minutes
If the window has expired, then it will increase the count - note SET Views = Views + 1
.
public static void TrackQueryView(string ipAddress, int querySetId)
{
if (IsNewView(ipAddress, querySetId))
{
Current.DB.Execute(@"
UPDATE
QuerySets
SET
Views = Views + 1
WHERE
Id = @querySetId",
new
{
querySetId
}
);
}
}
The call to isNewView is checking to see if the current QuerySet which is saved is relevant for the page based on the current time window.
public static bool IsNewView(string ipAddress, int revisionId)
{
string key = "qv - " + ipAddress + " " + revisionId;
bool isNewView = true;
int currentBracket = GetTimeBracket();
object cached = HttpRuntime.Cache.Get(key);
if (cached != null)
{
var cachedBracket = (int) cached;
if (cachedBracket == currentBracket || cachedBracket == (currentBracket - 1))
{
isNewView = false;
}
}
HttpRuntime.Cache.Insert(
key,
currentBracket,
null,
Cache.NoAbsoluteExpiration,
new TimeSpan(0, 0, VIEW_EXPIRES_SECS),
CacheItemPriority.High,
null
);
return isNewView;
}
This is how it used to be, I am fairly certain that it has changed. When content changed, the revisionId
would change, thereby changing the key and allowing a new view to count. However, this no longer happens so I am going to assume they patched that functionality. It is also possible that the network moved to a higher performance caching mechanism such as a self contained server farm solely for caching. One possibility would be that the window has drastically increased from 15 seconds to a significant amount of time.
Now, back to the exact scenario explained in the bounty for this question by LowerClassOverflowian. How can he have 1000 views in 3 months? Personally I think 5k rep in 3 months is pretty impressive, and the views relate to people who have benefited from the content produced by this user.
This was the best I could do from the outside looking in.
As far as I know, the profile counter increases when any new user visits your profile. The Stack Engine might be storing some data related to the user who visited your profile once and checks it next time if the user visits. If it's a new user your profile counter increases else remains the same. This is just a thought from my side that how it would be working, exactly Moderators might give a better idea.