You should rather use contentsums here than full source strings, these are fixed size strings which take less memory and are faster to lookup in the database. Also you currently fetch all values from the database, while it would be better to use ``.values_list('contensum', flat=True)`` to fetch only wanted field from the database.