@@ -2757,19 +2757,24 @@ def backup_issues(args, repo_cwd, repository, repos_template):
27572757 stale_timelines = find_stale_timeline_issues (
27582758 args , issue_cwd , repository , include_pulls = not should_include_pulls
27592759 )
2760- for number in sorted (stale_timelines - set (issues )):
2761- try :
2762- issues [number ] = retrieve_data (
2763- args , "{0}/{1}" .format (_issue_template , number ), paginated = False
2764- )[0 ]
2765- except (HTTPError , RepositoryUnavailableError , IndexError ) as e :
2766- # Deleted or transferred between the sweep and this fetch. The
2767- # refresh is opportunistic, so skip rather than fail the run.
2768- logger .warning (
2769- "Unable to refresh cross-references for issue {0}: {1}" .format (
2770- number , e
2771- )
2772- )
2760+
2761+ # Issues selected only by the cross-reference sweep have not otherwise
2762+ # changed. Reuse their complete stored payload and refresh only timeline_data.
2763+ # Fetching the issue, comments, events and attachments again turns the first
2764+ # --issue-timeline run into a near-full backup and can discard optional data
2765+ # when the corresponding flags are absent.
2766+ timeline_only_issues = stale_timelines - set (issues )
2767+ for number in sorted (timeline_only_issues ):
2768+ existing = read_json_file_if_exists (
2769+ "{0}/{1}.json" .format (issue_cwd , number )
2770+ )
2771+ if existing is None :
2772+ logger .warning (
2773+ "Unable to refresh cross-references for issue {0}: "
2774+ "stored issue data is unreadable" .format (number )
2775+ )
2776+ continue
2777+ issues [number ] = existing
27732778
27742779 if issues_skipped :
27752780 issues_skipped_message = " (skipped {0} pull requests)" .format (issues_skipped )
@@ -2784,6 +2789,7 @@ def backup_issues(args, repo_cwd, repository, repos_template):
27842789 timeline_template = _issue_template + "/{0}/timeline"
27852790 for number , issue in list (issues .items ()):
27862791 issue_file = "{0}/{1}.json" .format (issue_cwd , number )
2792+ timeline_only_refresh = number in timeline_only_issues
27872793 if (
27882794 args .incremental_by_files
27892795 and os .path .isfile (issue_file )
@@ -2799,10 +2805,14 @@ def backup_issues(args, repo_cwd, repository, repos_template):
27992805 )
28002806 continue
28012807
2802- if args .include_issue_comments or args .include_everything :
2808+ if not timeline_only_refresh and (
2809+ args .include_issue_comments or args .include_everything
2810+ ):
28032811 template = comments_template .format (number )
28042812 issues [number ]["comment_data" ] = retrieve_data (args , template )
2805- if args .include_issue_events or args .include_everything :
2813+ if not timeline_only_refresh and (
2814+ args .include_issue_events or args .include_everything
2815+ ):
28062816 template = events_template .format (number )
28072817 issues [number ]["event_data" ] = retrieve_data (args , template )
28082818 if include_timeline :
@@ -2815,7 +2825,7 @@ def backup_issues(args, repo_cwd, repository, repos_template):
28152825 for item in retrieve_data (args , template )
28162826 if item .get ("event" ) != "commented"
28172827 ]
2818- if args .include_attachments :
2828+ if args .include_attachments and not timeline_only_refresh :
28192829 download_attachments (
28202830 args , issue_cwd , issues [number ], number , repository , item_type = "issue"
28212831 )
0 commit comments