mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-13 17:08:06 -05:00
Events: add and use add_subreddit_fields function
Similar to add_target_fields, this standardizes the subreddit fields in one place so that every event doesn't have to know the multiple ones it should add.
This commit is contained in:
@@ -99,12 +99,6 @@ class EventQueue(object):
|
||||
|
||||
event.add("vote_direction", get_vote_direction_name(vote))
|
||||
|
||||
subreddit = vote.thing.subreddit_slow
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
self.add_target_fields(vote.thing)
|
||||
|
||||
if vote.previous_vote:
|
||||
event.add("prev_vote_direction",
|
||||
get_vote_direction_name(vote.previous_vote))
|
||||
@@ -121,6 +115,9 @@ class EventQueue(object):
|
||||
|
||||
event.add(name, value)
|
||||
|
||||
event.add_subreddit_fields(vote.thing.subreddit_slow)
|
||||
event.add_target_fields(vote.thing)
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
@@ -272,10 +269,7 @@ class EventQueue(object):
|
||||
event.add("parent_message_id", parent_message._id)
|
||||
event.add("parent_message_fullname", parent_message._fullname)
|
||||
|
||||
if subreddit:
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
event.add_subreddit_fields(subreddit)
|
||||
event.add_target_fields(target)
|
||||
|
||||
self.save_event(event)
|
||||
@@ -360,7 +354,6 @@ class EventQueue(object):
|
||||
)
|
||||
event.add("details_text", details_text)
|
||||
event.add("process_notes", "IN_TIMEOUT")
|
||||
event.add_target_fields(target)
|
||||
|
||||
from r2.models import Comment, Link, Subreddit
|
||||
if not subreddit:
|
||||
@@ -371,11 +364,9 @@ class EventQueue(object):
|
||||
elif isinstance(target, Subreddit):
|
||||
subreddit = target
|
||||
|
||||
if subreddit:
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
event.add_subreddit_fields(subreddit)
|
||||
event.add_target_fields(target)
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
@@ -400,9 +391,6 @@ class EventQueue(object):
|
||||
context=context,
|
||||
)
|
||||
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
if modaction.details_text:
|
||||
event.add("details_text", modaction.details_text)
|
||||
|
||||
@@ -414,6 +402,7 @@ class EventQueue(object):
|
||||
event["user_id"] = mod._id
|
||||
event["user_name"] = mod.name
|
||||
|
||||
event.add_subreddit_fields(subreddit)
|
||||
event.add_target_fields(target)
|
||||
|
||||
self.save_event(event)
|
||||
@@ -443,11 +432,9 @@ class EventQueue(object):
|
||||
if details_text:
|
||||
event.add("details_text", details_text)
|
||||
|
||||
if subreddit:
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
event.add_subreddit_fields(subreddit)
|
||||
event.add_target_fields(target)
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
@@ -475,9 +462,6 @@ class EventQueue(object):
|
||||
else:
|
||||
event.add("verified_email", False)
|
||||
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
# Due to the redirect, the request object being sent isn't the
|
||||
# original, so referrer and action data is missing for certain events
|
||||
if request and (event_type == "quarantine_interstitial_view" or
|
||||
@@ -495,6 +479,8 @@ class EventQueue(object):
|
||||
if thing_id36:
|
||||
event.add("thing_id", int(thing_id36, 36))
|
||||
|
||||
event.add_subreddit_fields(subreddit)
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
@@ -601,6 +587,13 @@ class EventV2(object):
|
||||
self.add("target_created_ts",
|
||||
_epoch_to_millis(epoch_timestamp(target._date)))
|
||||
|
||||
def add_subreddit_fields(self, subreddit):
|
||||
if not subreddit:
|
||||
return
|
||||
|
||||
self.add("sr_id", subreddit._id)
|
||||
self.add("sr_name", subreddit.name)
|
||||
|
||||
def get(self, field, obfuscated=False):
|
||||
if obfuscated:
|
||||
return self.obfuscated_data.get(field, None)
|
||||
|
||||
Reference in New Issue
Block a user