#NEWLINE# def _aggregate_category_tags( categories ) : #NEWLINE# #INDENT# 'Mutates categories with the tags that belong to each category.\n\n    For each category, we derive all the tags that belong to that category by\n    merging the tags of all the plugins of that category.\n    ' #NEWLINE# for category in categories : #NEWLINE# #INDENT# category_plugins = r . table ( 'plugins' ) . filter ( { #NEWLINE# #INDENT# 'category' : category [ 'id' ] , #NEWLINE# #UNINDENT# } ) . pluck ( 'tags' ) . run ( r_conn ( ) ) #NEWLINE# tags_counter = collections . Counter ( ) #NEWLINE# for plugin in category_plugins : #NEWLINE# #INDENT# tags_counter . update ( plugin [ 'tags' ] ) #NEWLINE# #UNINDENT# category [ 'tags' ] = [ { #NEWLINE# #INDENT# 'id' : k , #NEWLINE# 'count' : v , #NEWLINE# #UNINDENT# } for ( k , v ) in tags_counter . most_common ( ) ]