Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
Bundle vote information processed in queues
Browse files Browse the repository at this point in the history
This change updates vote queue processing code to pass down
the dict loaded as JSON from the queue, making it easier to
plumb through additional data as desired.
  • Loading branch information
kemitche committed May 5, 2015
1 parent d642330 commit 1497601
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 4 additions & 6 deletions r2/r2/lib/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,16 +1798,15 @@ def get_likes(user, requested_items):

return res

def handle_vote(user, thing, dir, ip, vote_info,
cheater=False, foreground=False, timer=None, date=None):

def handle_vote(user, thing, vote, foreground=False, timer=None, date=None):
if timer is None:
timer = SimpleSillyStub()

from r2.lib.db import tdb_sql
from sqlalchemy.exc import IntegrityError
try:
v = cast_vote(user, thing, dir, ip, vote_info=vote_info,
cheater=cheater, timer=timer, date=date)
v = cast_vote(user, thing, vote, timer=timer, date=date)
except (tdb_sql.CreationError, IntegrityError):
g.log.error("duplicate vote for: %s" % str((user, thing, dir)))
return
Expand Down Expand Up @@ -1876,8 +1875,7 @@ def _handle_vote(msg):
if isinstance(votee, (Link, Comment)):
print (voter, votee, vote["dir"], vote["ip"], vote["info"],
vote["cheater"])
handle_vote(voter, votee, vote["dir"], vote["ip"], vote["info"],
cheater=vote["cheater"], foreground=True, timer=timer,
handle_vote(voter, votee, vote, foreground=True, timer=timer,
date=date)

if isinstance(votee, Comment):
Expand Down
9 changes: 5 additions & 4 deletions r2/r2/models/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def create(cls, votee_fullname, voter_id36, ip):
cls._set_values(votee_fullname, {voter_id36: ip})


def cast_vote(sub, obj, dir, ip, vote_info, cheater, timer, date):
def cast_vote(sub, obj, vote_info, timer, date):
from r2.models.admintools import valid_user, valid_thing, update_score
from r2.lib.count import incr_sr_count

Expand All @@ -242,11 +242,11 @@ def cast_vote(sub, obj, dir, ip, vote_info, cheater, timer, date):
vote = Storage(
_thing1=sub,
_thing2=obj,
_name=names_by_dir[dir],
_name=names_by_dir[vote_info["dir"]],
_date=date,
valid_thing=True,
valid_user=True,
ip=ip,
ip=vote_info["ip"],
)

# these track how much ups/downs should change on `obj`
Expand Down Expand Up @@ -282,7 +282,8 @@ def cast_vote(sub, obj, dir, ip, vote_info, cheater, timer, date):
karma = sub.karma(kind, sr)

if vote.valid_thing:
vote.valid_thing = valid_thing(vote, karma, cheater, vote_info)
vote.valid_thing = valid_thing(vote, karma, vote_info["cheater"],
vote_info["info"])

if vote.valid_user:
vote.valid_user = vote.valid_thing and valid_user(vote, sr, karma)
Expand Down

0 comments on commit 1497601

Please sign in to comment.