docbrown/app
Jeremy Friesen 6d37f4303c
Favoring single SQL and computation over enum (#15865)
* Favoring single SQL and computation over enum

Prior to this commit, we ran a SQL statement to generate a list of
articles then applied some minor randomization.

With this commit, I'm removing the randomization in favor of expected
values, and collapsing the result set into a single inline SQL and some
post query simple arithmatic.

Let's check my math.  For each article we sum:

* `article.score`
* `article.comments_count` * 14
* a random number between 0 and 5 (`rand(6)`) with expected value of 2.5
* the tag's (taggings_count + 1) / 2

The new SQL query sums the `article.score` and the
`article.comments_count` * 14.  I then reduce the remainder of the
equation.  From "for each article sum `(rand(5) + (taggings_count + 1) /
2)`" we have the following:

`article_count * (2.5 + (taggings_count + 1) / 2)`

Which is equivalent to:

`article_count * ((taggings_count + 1 + (2.5 * 2)) / 2)`

Which is equivalent to:

`article_count * ((taggings_count + 6) / 2)`

This change reduces computation time by favoring expected values.

* Fixing broken behavior and adding comments
2021-12-22 14:59:37 -05:00
..
assets Add catch to trackAdImpression() (#15864) 2021-12-22 13:12:37 -05:00
black_box Make Rubocop happy again (#14729) 2021-09-14 09:15:01 -05:00
components/admin/users Small change to make the tools section of member details mobile friendly. (#15159) 2021-10-22 18:47:20 +02:00
controllers Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
decorators role deprecation cleanup (#15717) 2021-12-09 15:27:45 -06:00
errors Guarding against spam from OAuth Sources (#15404) 2021-11-18 16:26:39 -05:00
forms Using a Form Object that will persist for the Creator Settings Form (#15684) 2021-12-10 17:07:40 +02:00
helpers Escape periods and display the group name properly (#15819) 2021-12-17 17:35:42 -05:00
javascript Bump eslint-config-preact from 1.2.0 to 1.3.0 (#15834) 2021-12-21 14:42:20 +00:00
lib ✂️✂️✂️ Drop PWA (#15781) 2021-12-15 21:25:04 +01:00
liquid_tags Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
mailers ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
models Favoring single SQL and computation over enum (#15865) 2021-12-22 14:59:37 -05:00
policies Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
queries Favoring common method not previously available (#15855) 2021-12-22 11:00:54 -05:00
refinements Drop profile columns from user (#10707) 2020-12-03 08:14:38 +07:00
sanitizers Extracting container for allowed tags & attrs (#15338) 2021-12-16 12:24:45 -05:00
serializers ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
services User correct username in mobile mention notifications (#15861) 2021-12-22 10:31:22 -06:00
uploaders Added the logo upload to the admin -> customization -> config -> images section. (#15729) 2021-12-15 14:10:27 -05:00
validators Don't raise error when empty community emoji setting submitted (#15723) 2021-12-17 09:29:55 -06:00
view_objects Upgrade to Ruby 3.0.2 (#12103) 2021-08-25 14:26:33 -04:00
views Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
workers Use the tag_list method, rather than the cached_tag_list attribute (#15638) 2021-12-03 14:47:42 -06:00