We have a requirement in which we must get values from
mongo db faster than the current scenario. We have few articles in our project and there is an option to fetch recent articles which are most popular ones. Popularity of articles are found by querying interaction table from mongo db and sorting articles based on the values. So more visit to an article increases its value and it becomes more popular.
We are using
mongodb driver to connect to mongodb. Below is the code for getting interactions.
var query = MongoDB.Driver.Builders.Query.And( MongoDB.Driver.Builders.Query.GTE( Constants.AnalyticsInteractionsFields.StartDateTime, DateTime.Now.AddDays(-dayscount)), MongoDB.Driver.Builders.Query.EQ( Constants.AnalyticsInteractionsFields.SiteName, Sitecore.Context.Site.Name)); var interactions = driver.Interactions.FindAs<VisitData>(query);`
Since looking up in large table like Interaction table takes a considerable amount of time (around 30 -35 secs) we have to reduce the time to approximately around 3-5 secs.
We have decided to follow 2 approaches as described below.
- Instead of querying mongodb, we can query
Fact_PageViewstable from SQL table and sort according to the values.
- Write a scheduler which runs in every 20 mins to fetch the data from mongo db and host it as a service. Whenever request for most popular articles comes, call the service and get the latest set of articles from it.
Please suggest which is best approach or is there any other approach we can follow to speed up the process.