Skip to content

Instantly share code, notes, and snippets.

View tommarshall's full-sized avatar

Tom Marshall tommarshall

View GitHub Profile
@tsabat
tsabat / 1_justification.md
Last active September 16, 2017 11:06
View Counts in MySql

We store views in a single MySQL row, indexed by the redis key. Without redis in front of the DB this would cause lock contention, but redis keeps us reading/writing to the DB on the first, 10th, 25, and mod 100th read.

Without redis backing, using a single row to store counts would cause lock contention.

Using a row per view would result in slow reads on count(*) and in a write-heavy situation will cause the re-index to slow/stop replication because indexes are single-threaded.

@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active September 23, 2024 03:01
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems: