WikiEducationFoundation / WikiEduDashboard

Wiki Education Foundation's Wikipedia course dashboard system
https://dashboard.wikiedu.org
MIT License
392 stars 631 forks source link

[Data rearchitecture] Reimplement view count based on first revision #6043

Closed gabina closed 3 days ago

gabina commented 3 days ago

What this PR does

This PR re-implements the view counts metric for individual articles and courses that was removed in #6037. Now the view count is based on a new ArticlesCourses field called first_revision. The calculation is done as follows: ((Time.now.utc.to_date - first_revision.to_date).to_i * average_views).to_i, where first_revision is a new field and average_views is the already existing field in the Articles model.

The idea behind this approach is to avoid having to update the articles courses caches for each article course when updating a course (there are courses with 45K articles courses, so making 45K queries is costly).

Now the first_revision field is populated when the article course is created, and the view_count for an individual article course is calculated dynamically through a new view_count method in the app/helpers/article_helper.rb.

To calculate the view_sum field now we have to calculate the individual view_count for each article course and add them together. This is done through the lib/course_cache_manager.rb entirely in the SQL side because that way is much faster. Note that article course field view_count is no longer used.

Open questions and concerns

< anything you learned that you want to share, or questions you're wondering about related to this PR >