Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Reduce spam.
Browse files Browse the repository at this point in the history
This adds a notify boolean to one of the Preference modifiers that will let us
turn off fedmsg messages for all but one of the initial operations that goes
into creating a new account.  This should reduce spam on the message bus.

This is especially important because these messages cause the fmn backend to
*invalidate its own cache*, thus slowing it down dramatically.  There is no
need for it to invalidate its own cache *20 times* for a new user.  It should
only need to do it once.
  • Loading branch information
ralphbean committed Jul 18, 2014
1 parent 32f7dd4 commit 97296a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 8 additions & 10 deletions fmn/lib/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,25 @@ def contexts():
if not pref:
pref = fmn.lib.models.Preference.create(session, user, context)

# Provide one catchall before adding the more specific rules below
name = 'Anything involving my username'
rule_path = 'fmn.rules:user_filter'
filt = fmn.lib.models.Filter.create(session, name)
filt.add_rule(session, valid_paths, rule_path, fasnick=nick)
pref.add_filter(session, filt)

# Add rules that look for this user
qualifier_path = 'fmn.rules:user_filter'
for name, rule_path in generic_rule_path_defaults:
filt = fmn.lib.models.Filter.create(session, name)
filt.add_rule(session, valid_paths, rule_path)
filt.add_rule(session, valid_paths, qualifier_path, fasnick=nick)

pref.add_filter(session, filt)
pref.add_filter(session, filt, notify=False)

# Add rules that look for this user's packages
qualifier_path = 'fmn.rules:user_package_filter'
for name, rule_path in package_rule_path_defaults:
filt = fmn.lib.models.Filter.create(session, name)
filt.add_rule(session, valid_paths, rule_path)
filt.add_rule(session, valid_paths, qualifier_path, fasnick=nick)
pref.add_filter(session, filt, notify=False)

pref.add_filter(session, filt)
# Lastly, provide one catchall
name = 'Anything involving my username'
rule_path = 'fmn.rules:user_filter'
filt = fmn.lib.models.Filter.create(session, name)
filt.add_rule(session, valid_paths, rule_path, fasnick=nick)
pref.add_filter(session, filt, notify=True)
5 changes: 3 additions & 2 deletions fmn/lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,12 @@ def delete_filter(self, session, filter_name):
session.commit()
self.notify(self.openid, self.context_name, "filters")

def add_filter(self, session, filter):
def add_filter(self, session, filter, notify=True):
self.filters.append(filter)
session.flush()
session.commit()
self.notify(self.openid, self.context_name, "filters")
if notify:
self.notify(self.openid, self.context_name, "filters")

def has_filter_name(self, session, filter_name):
for filter in self.filters:
Expand Down

0 comments on commit 97296a8

Please sign in to comment.