def _sync_db_and_registry(qs, app_id):
 existing = dict(((m.module, m) for m in qs))
 to_add = [m for m in module_registry if (m not in existing)]
 to_delete = [m for m in existing if (m not in module_registry)]
 for m in to_add:
  DiscoveryModule.objects.get_or_create(module=m, app=app_id)
 DiscoveryModule.objects.filter(module__in=to_delete, app=app_id).delete()
 if (to_add or to_delete):
  qs._result_cache = None

def _sync_db_and_registry ( qs , app_id ) : existing = dict ( ( ( m . module , m ) for m in qs ) ) to_add = [ m for m in module_registry if ( m not in existing ) ] to_delete = [ m for m in existing if ( m not in module_registry ) ] for m in to_add : DiscoveryModule . objects . get_or_create ( module = m , app = app_id ) DiscoveryModule . objects . filter ( module__in = to_delete , app = app_id ) . delete ( ) if ( to_add or to_delete ) : qs . _result_cache = None
match up the module registry and discoverymodule rows in the db .