|
26 | 26 | ) |
27 | 27 | from libraries.constants import SUB_LIBRARIES |
28 | 28 | from mailing_list.models import EmailData |
29 | | -from .utils import batched |
| 29 | +from .utils import batched, conditional_batched |
30 | 30 |
|
31 | 31 |
|
32 | 32 | class LibraryForm(ModelForm): |
@@ -668,6 +668,31 @@ def _get_dependency_data(self, library_order, version): |
668 | 668 | diffs.append(diffs_by_id.get(lib_id, {})) |
669 | 669 | return diffs |
670 | 670 |
|
| 671 | + def get_library_data(self, libraries, library_order, prior_version, version): |
| 672 | + library_data = [ |
| 673 | + { |
| 674 | + "library": item[0], |
| 675 | + "full_count": item[1], |
| 676 | + "version_count": item[2], |
| 677 | + "top_contributors_release": item[3], |
| 678 | + "new_contributors_count": item[4], |
| 679 | + "issues": item[5], |
| 680 | + "library_version": item[6], |
| 681 | + "deps": item[7], |
| 682 | + } |
| 683 | + for item in zip( |
| 684 | + libraries, |
| 685 | + self._get_library_full_counts(libraries, library_order), |
| 686 | + self._get_library_version_counts(library_order, version), |
| 687 | + self._get_top_contributors_for_library_version(library_order, version), |
| 688 | + self._count_new_contributors(libraries, library_order, version), |
| 689 | + self._count_issues(libraries, library_order, version, prior_version), |
| 690 | + self._get_library_versions(library_order, version), |
| 691 | + self._get_dependency_data(library_order, version), |
| 692 | + ) |
| 693 | + ] |
| 694 | + return [x for x in library_data if x["version_count"]["commit_count"] > 0] |
| 695 | + |
671 | 696 | def get_stats(self): |
672 | 697 | report_configuration = self.cleaned_data["report_configuration"] |
673 | 698 | version = Version.objects.filter(name=report_configuration.version).first() |
@@ -713,31 +738,16 @@ def get_stats(self): |
713 | 738 | ) |
714 | 739 | ) |
715 | 740 |
|
716 | | - library_data = [ |
717 | | - { |
718 | | - "library": item[0], |
719 | | - "full_count": item[1], |
720 | | - "version_count": item[2], |
721 | | - "top_contributors_release": item[3], |
722 | | - "new_contributors_count": item[4], |
723 | | - "issues": item[5], |
724 | | - "library_version": item[6], |
725 | | - "deps": item[7], |
726 | | - } |
727 | | - for item in zip( |
728 | | - libraries, |
729 | | - self._get_library_full_counts(libraries, library_order), |
730 | | - self._get_library_version_counts(library_order, version), |
731 | | - self._get_top_contributors_for_library_version(library_order, version), |
732 | | - self._count_new_contributors(libraries, library_order, version), |
733 | | - self._count_issues(libraries, library_order, version, prior_version), |
734 | | - self._get_library_versions(library_order, version), |
735 | | - self._get_dependency_data(library_order, version), |
736 | | - ) |
737 | | - ] |
738 | | - library_data = [ |
739 | | - x for x in library_data if x["version_count"]["commit_count"] > 0 |
740 | | - ] |
| 741 | + library_data = self.get_library_data( |
| 742 | + libraries, library_order, prior_version, version |
| 743 | + ) |
| 744 | + AUTHORS_PER_PAGE_THRESHOLD = 6 |
| 745 | + batched_library_data = conditional_batched( |
| 746 | + library_data, |
| 747 | + 2, |
| 748 | + lambda x: x.get("top_contributors_release").count() |
| 749 | + <= AUTHORS_PER_PAGE_THRESHOLD, |
| 750 | + ) |
741 | 751 | top_contributors = self._get_top_contributors_for_version(version) |
742 | 752 | # total messages sent during this release (version) |
743 | 753 | total_mailinglist_count = EmailData.objects.filter(version=version).aggregate( |
@@ -840,6 +850,7 @@ def get_stats(self): |
840 | 850 | "version_commit_count": version_commit_count, |
841 | 851 | "top_contributors_release_overall": top_contributors, |
842 | 852 | "library_data": library_data, |
| 853 | + "batched_library_data": batched_library_data, |
843 | 854 | "top_libraries_for_version": top_libraries_for_version, |
844 | 855 | "library_count": library_count, |
845 | 856 | "library_count_prior": library_count_prior, |
|
0 commit comments