utils.py 484 B

123456789101112131415
  1. # Copyright © 2023 Ingram Micro Inc. All rights reserved.
  2. def batch_qs(qs, batch_size=10000):
  3. """
  4. Helper function to manage RAM usage on big dataset iterations.
  5. This function can be used only on STATIC DB state. It's a good fit for migrations, but
  6. it can't be used in real applications.
  7. """
  8. assert batch_size > 0
  9. total = qs.count()
  10. for start in range(0, total, batch_size):
  11. end = min(start + batch_size, total)
  12. yield qs[start:end]