[Answer]-Reducing memory consumption in django models, extra fields versus extra operations

1👍

You need to consider both the data size and the changing requirement.

If the hotness definition remains in a certain period, I will chose to have a hotness field, since it ease the selection part.

If the definition of hotness is easy to change, I prefer to have get_hotness() method, since it doesn’t required to update pre-calculated hotness data in database.

And the data size is another concern, if you need sort the entire elements by hotness, the may easily exceed the memory limit when loading all data into memory with Models.object.all().

Leave a comment