Hacker News new | ask | show | jobs
by tommikaikkonen 3185 days ago
What was the optimization?
1 comments

Our version of shell_plus was trying to handle aliased models that were defined in settings.py.

In order to do this, it was maintaining a map of {appName: [list of imports]}.

When constructing this map, for some reason, it n^2 the imports - i.e., if an app "foo" had models "Bar", "Foo", "FooBar", then the import strings were, "from foo import Bar; from foo import Bar, Foo; from foo import Bar, Foo, FooBar" instead of "from foo import Bar, Foo, FooBar". Some apps had 50+ models, so instead of 1 import line for these 50 models, it was executing 2500 import lines. I fixed this so that it executed only one import line instead n^2 import lines.