1
- import asyncio
2
1
import copy
3
2
import functools
4
3
import json
17
16
from shared .api_archive .archive import ArchiveService
18
17
from shared .helpers .yaml import walk
19
18
from shared .reports .types import ReportTotals
19
+ from shared .torngit .base import TorngitBaseAdapter
20
20
from shared .utils .merge import LineType , line_type
21
21
22
22
from compare .models import CommitComparison
@@ -646,6 +646,12 @@ def __init__(self, user, base_commit, head_commit):
646
646
self ._base_commit = base_commit
647
647
self ._head_commit = head_commit
648
648
649
+ @cached_property
650
+ def _adapter (self ) -> TorngitBaseAdapter :
651
+ return RepoProviderService ().get_adapter (
652
+ owner = self .user , repo = self .base_commit .repository
653
+ )
654
+
649
655
def validate (self ):
650
656
# make sure head and base reports exist (will throw an error if not)
651
657
self .head_report
@@ -676,10 +682,7 @@ def get_file_comparison(self, file_name, with_src=False, bypass_max_diff=False):
676
682
base_file = None
677
683
678
684
if with_src :
679
- adapter = RepoProviderService ().get_adapter (
680
- owner = self .user , repo = self .base_commit .repository
681
- )
682
- file_content = async_to_sync (adapter .get_source )(
685
+ file_content = async_to_sync (self ._adapter .get_source )(
683
686
file_name , self .head_commit .commitid
684
687
)["content" ]
685
688
# make sure the file is str utf-8
@@ -697,9 +700,14 @@ def get_file_comparison(self, file_name, with_src=False, bypass_max_diff=False):
697
700
bypass_max_diff = bypass_max_diff ,
698
701
)
699
702
700
- @property
701
- def git_comparison (self ):
702
- return self ._fetch_comparison [0 ]
703
+ @cached_property
704
+ def git_comparison (self ) -> dict :
705
+ """
706
+ Fetches comparison, and caches the result.
707
+ """
708
+ return async_to_sync (self ._adapter .get_compare )(
709
+ self .base_commit .commitid , self .head_commit .commitid
710
+ )
703
711
704
712
@cached_property
705
713
def base_report (self ):
@@ -803,23 +811,6 @@ def upload_commits(self):
803
811
commits_queryset .exclude (deleted = True )
804
812
return commits_queryset
805
813
806
- @cached_property
807
- def _fetch_comparison (self ):
808
- """
809
- Fetches comparison, and caches the result.
810
- """
811
- adapter = RepoProviderService ().get_adapter (
812
- self .user , self .base_commit .repository
813
- )
814
- comparison_coro = adapter .get_compare (
815
- self .base_commit .commitid , self .head_commit .commitid
816
- )
817
-
818
- async def runnable ():
819
- return await asyncio .gather (comparison_coro )
820
-
821
- return async_to_sync (runnable )()
822
-
823
814
def flag_comparison (self , flag_name ):
824
815
return FlagComparison (self , flag_name )
825
816
0 commit comments