@@ -12,7 +12,7 @@ use std::fs::File;
1212use std:: io:: { ErrorKind , Write } ;
1313use std:: sync:: Arc ;
1414use std:: time:: Instant ;
15- use tracing:: { debug, info, instrument} ;
15+ use tracing:: { debug, info, instrument, warn } ;
1616
1717#[ derive( Serialize , Deserialize ) ]
1818pub struct SyncToGitIndex {
@@ -121,9 +121,28 @@ impl BackgroundJob for SyncToSparseIndex {
121121 let future = env. storage . sync_index ( & self . krate , content) ;
122122 future. await . context ( "Failed to sync index data" ) ?;
123123
124- if env. cloudfront ( ) . is_some ( ) {
125- let path = Repository :: relative_index_file_for_url ( & self . krate ) ;
124+ let path = Repository :: relative_index_file_for_url ( & self . krate ) ;
125+
126+ if let Some ( fastly) = env. fastly ( )
127+ && env. config . sparse_index_fastly_enabled
128+ {
129+ let domain_name = & env. config . domain_name ;
130+ let domains = [
131+ format ! ( "index.{}" , domain_name) ,
132+ format ! ( "fastly-index.{}" , domain_name) ,
133+ ] ;
134+
135+ for domain in domains {
136+ if let Err ( error) = fastly. purge ( & domain, & path) . await {
137+ warn ! (
138+ domain,
139+ path, "Failed to invalidate sparse index on Fastly: {error}"
140+ ) ;
141+ }
142+ }
143+ }
126144
145+ if env. cloudfront ( ) . is_some ( ) {
127146 info ! ( %path, "Queuing index file invalidation on CloudFront" ) ;
128147
129148 let paths = & [ path] ;
0 commit comments