Skip to content

Commit

Permalink
Added small optimization to downcast_plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
czpython committed Aug 25, 2016
1 parent db2b69b commit aabeb75
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cms/utils/plugins.py
Expand Up @@ -147,12 +147,14 @@ def downcast_plugins(plugins,
placeholders=None, request=None):
plugin_types_map = defaultdict(list)
plugin_lookup = {}
plugin_ids = []

# make a map of plugin types, needed later for downcasting
for plugin in plugins:
plugin_types_map[plugin.plugin_type].append(plugin.pk)

# Keep track of the plugin ids we've received
plugin_ids = list(plugin_types_map.values())

This comment has been minimized.

Copy link
@piotrjakimiak

piotrjakimiak Aug 25, 2016

Contributor

Is it list of ids or list of list of ids?

plugin_types_map = defaultdict(list)
plugin_types_map[0].append(0)
plugin_types_map[1].append(1)
list(plugin_types_map.values())
[[0], [1]]

This comment has been minimized.

Copy link
@piotrjakimiak

piotrjakimiak Aug 25, 2016

Contributor

BTW, creating set instead of list will result in faster lookups.

This comment has been minimized.

Copy link
@czpython

czpython Aug 25, 2016

Author Contributor

list of ids.
was fixed by e686f74


placeholders = placeholders or []
placeholders_by_id = {placeholder.pk: placeholder for placeholder in placeholders}

Expand All @@ -161,9 +163,6 @@ def downcast_plugins(plugins,
# get all the plugins of type cls.model
plugin_qs = cls.get_render_queryset().filter(pk__in=pks)

# Keep track of the plugin ids we've received
plugin_ids.extend(plugin_ids)

# put them in a map so we can replace the base CMSPlugins with their
# downcasted versions
for instance in plugin_qs.iterator():
Expand Down

0 comments on commit aabeb75

Please sign in to comment.