Acts As Most Popular

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Acts As Most Popular - Presentation Transcript

    1. acts_as_most_popular Wolfram Arnold RubyFocus
    2. User Activity Tracking
      • Join between:
        • Viewable entity
          • (user profile, image, post, video ...)
        • Activity tracking
          • (viewings, comments, ratings ...)
      • Item.find(:all,
      • :select => 'items.*,
      • COUNT(*) AS viewing_count',
      • :joins => :viewings,
      • :limit => limit,
      • :group => 'viewings.item_id',
      • :order => 'viewing_count DESC')
      • acts_as_most_popular
    3. acts_as_most_popular
      • I want:
        • Most popular list from cache
        • Cache populared from database once
        • List automatically kept sorted & indexed in cache
      • I need:
        • A caching framework
        • Ideally something common, transparent & flexible
    4. Cache Money
    5. Cache Money
      • Transparent
        • find vs. get_cache
      • Sequence
        • AR Cache SQL
        • find -> get -> select
        • update -> set -> update
        • create -> add -> insert
        • destroy -> delete/expire -> delete
      • Maintains indices automatically!
    6. Cache Money
      • Instance methods on models:
        • get
        • set
        • repository
      • Automatic key handling
        • User.set(“new_key”)
        • -> Key: “User:1/new_key”
    7. Solution
    8. acts_as_most_popular
      • Additional index, sorted by activity count
        • primed on first access
        • maintained via after_add, after_remove callbacks
    9. Definition
      • class Item < ActiveRecord::Base
      • has_many :viewings
      • acts_as_most_popular
      • :activity_association => :viewings,
      • :limit => 5,
      • :db_finder_args =>
      • { :select => 'item_id,
      • COUNT(*) AS activity_count',
      • :group => 'item_id' }
      • end
    10. Usage
      • class StatsController < Application
      • def most_popular
      • @items = Item.most_popular
      • end
      • end
    11. References
      • Cache Money
      • http://magicscalingsprinkles.wordpress.com/2008/12/11/introducing-cache-money/
      • http://github.com/nkallen/cache-money/tree/master
      • Images
      • http://www.flickr.com/photos/flirtykitty/142229288/
      • http://www.flickr.com/photos/jojakeman/2434236126/
      • Thank You!
      • Wolfram Arnold
      • RubyFocus
      • [email_address]
    SlideShare Zeitgeist 2009

    + Wolfram ArnoldWolfram Arnold Nominate

    custom

    439 views, 0 favs, 0 embeds more stats

    Presenting acts_as_most_popular: A plugin to cache more

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 439
      • 439 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 7
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories