Skip to content

Commit

Permalink
removed debugger statements and added internal caching
Browse files Browse the repository at this point in the history
  • Loading branch information
PirosB3 committed Jun 27, 2014
1 parent ae19dfd commit 69b292a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion django/db/migrations/autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ def generate_deleted_models(self):
model = self.old_apps.get_model(app_label, model_name)
# Gather related fields
related_fields = {}
import ipdb; ipdb.set_trace()
for field in model._meta.local_fields:
if field.rel:
if field.rel.to:
Expand Down
20 changes: 14 additions & 6 deletions django/db/models/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ def non_swapped_models(self):
#@cached_property
@property
def _field_map(self):
types = ALL
res = {}
for field, names in self.get_new_fields(types=types, recursive=True).iteritems():
for name in names:
res[name] = field
return res
try:
return self._field_map_cache
except AttributeError:
types = ALL
res = {}
for field, names in self.get_new_fields(types=types, recursive=True).iteritems():
for name in names:
res[name] = field
self._field_map_cache = res
return res

def get_new_field(self, field_name):
try:
Expand Down Expand Up @@ -322,6 +326,10 @@ def _prepare(self, model):
def _expire_cache(self):
#if hasattr(self, '_field_map'):
#del self._field_map
try:
del self._field_map_cache
except AttributeError:
pass
self._get_new_fields_cache = {}

def add_field(self, field):
Expand Down
1 change: 0 additions & 1 deletion tests/migrations/test_autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ def test_foreign_key_removed_before_target_model(self):
after = self.make_project_state([self.author_name]) # removes both the model and FK
autodetector = MigrationAutodetector(before, after)
changes = autodetector._detect_changes()
import ipdb; ipdb.set_trace()
# Right number of migrations?
self.assertEqual(len(changes['testapp']), 1)
# Right number of actions?
Expand Down

0 comments on commit 69b292a

Please sign in to comment.