@@ -381,7 +381,11 @@ class PackageBackend {
381
381
return true ;
382
382
});
383
383
if (updated) {
384
- await purgePackageCache (package);
384
+ triggerPackagePostUpdates (
385
+ package,
386
+ skipReanalysis: true ,
387
+ skipExport: true ,
388
+ );
385
389
}
386
390
return updated;
387
391
}
@@ -480,9 +484,7 @@ class PackageBackend {
480
484
options: optionsChanges,
481
485
));
482
486
});
483
- await purgePackageCache (package);
484
- await taskBackend.trackPackage (package);
485
- await apiExporter.synchronizePackage (package);
487
+ triggerPackagePostUpdates (package, skipVersionsExport: true );
486
488
}
487
489
488
490
/// Updates [options] on [package] /[version] , assuming the current user
@@ -520,10 +522,9 @@ class PackageBackend {
520
522
authenticatedUser, tx, p, pv, options.isRetracted! );
521
523
}
522
524
});
523
- await purgePackageCache (package);
524
525
await purgeScorecardData (package, version,
525
526
isLatest: pkg.latestVersion == version);
526
- await apiExporter. synchronizePackage (package);
527
+ triggerPackagePostUpdates (package);
527
528
}
528
529
529
530
/// Verifies an update to the credential-less publishing settings and
@@ -780,15 +781,18 @@ class PackageBackend {
780
781
return _asPackagePublisherInfo (package);
781
782
});
782
783
await purgePublisherCache (publisherId: request.publisherId);
783
- await purgePackageCache (packageName);
784
784
785
785
if (email != null ) {
786
786
await emailBackend.trySendOutgoingEmail (email! );
787
787
}
788
788
if (currentPublisherId != null ) {
789
789
await purgePublisherCache (publisherId: currentPublisherId);
790
790
}
791
- await apiExporter.synchronizePackage (packageName);
791
+ triggerPackagePostUpdates (
792
+ packageName,
793
+ skipReanalysis: true ,
794
+ skipVersionsExport: true ,
795
+ );
792
796
return rs;
793
797
}
794
798
@@ -1299,7 +1303,7 @@ class PackageBackend {
1299
1303
sw.reset ();
1300
1304
1301
1305
_logger.info ('Invalidating cache for package ${newVersion .package }.' );
1302
- await purgePackageCache (newVersion.package);
1306
+ triggerPackagePostUpdates (newVersion.package, taskUpdateDependents : true );
1303
1307
1304
1308
// Let's not block the upload response on these post-upload tasks.
1305
1309
// The operations should either be non-critical, or should be retried
@@ -1324,12 +1328,10 @@ class PackageBackend {
1324
1328
await Future .wait ([
1325
1329
if (activeConfiguration.isPublishedEmailNotificationEnabled)
1326
1330
emailBackend.trySendOutgoingEmail (outgoingEmail),
1327
- taskBackend.trackPackage (newVersion.package, updateDependents: true ),
1328
- apiExporter.synchronizePackage (newVersion.package),
1329
1331
apiExporter.synchronizeAllPackagesAtomFeed (),
1332
+ tarballStorage.updateContentDispositionOnPublicBucket (
1333
+ newVersion.package, newVersion.version! ),
1330
1334
]);
1331
- await tarballStorage.updateContentDispositionOnPublicBucket (
1332
- newVersion.package, newVersion.version! );
1333
1335
} catch (e, st) {
1334
1336
final v = newVersion.qualifiedVersionKey;
1335
1337
_logger.severe ('Error post-processing package upload $v ' , e, st);
@@ -1581,7 +1583,8 @@ class PackageBackend {
1581
1583
package: packageName,
1582
1584
));
1583
1585
});
1584
- await purgePackageCache (packageName);
1586
+ triggerPackagePostUpdates (packageName,
1587
+ skipReanalysis: true , skipExport: true );
1585
1588
}
1586
1589
1587
1590
Future <void > _validatePackageUploader (
@@ -1657,7 +1660,8 @@ class PackageBackend {
1657
1660
uploaderUser: uploader,
1658
1661
));
1659
1662
});
1660
- await purgePackageCache (packageName);
1663
+ triggerPackagePostUpdates (packageName,
1664
+ skipReanalysis: true , skipExport: true );
1661
1665
return api.SuccessMessage (
1662
1666
success: api.Message (
1663
1667
message:
@@ -2096,3 +2100,49 @@ class _VersionTransactionDataAcccess {
2096
2100
return await _tx.query <PackageVersion >(pkgKey).run ().toList ();
2097
2101
}
2098
2102
}
2103
+
2104
+ /// Triggers post-update event processing after a [Package] object is part of
2105
+ /// a transaction.
2106
+ ///
2107
+ /// Returns a record with an optionally awaitable [Future] in case the caller needs to
2108
+ /// wait for the updates before yielding its response.
2109
+ ({Future future}) triggerPackagePostUpdates (
2110
+ String package, {
2111
+ /// Skip trigger a new analysis on the package.
2112
+ bool skipReanalysis = false ,
2113
+
2114
+ /// Skip triggering a new export to the CDN bucket.
2115
+ bool skipExport = false ,
2116
+
2117
+ /// Skip only the version-related exports to the CDN bucket, keeps the
2118
+ /// package-related operations.
2119
+ /// TODO: implement this in API exporter.
2120
+ bool skipVersionsExport = false ,
2121
+
2122
+ /// Pass the force-deletion flag to the package export operation.
2123
+ bool exportForceDelete = false ,
2124
+
2125
+ /// Pass the update-dependents flag to the task update operation.
2126
+ bool taskUpdateDependents = false ,
2127
+ }) {
2128
+ Future add (Future Function () fn) {
2129
+ return asyncQueue.addAsyncFn (fn).future;
2130
+ }
2131
+
2132
+ final futures = [
2133
+ add (() => purgePackageCache (package)),
2134
+ if (! skipReanalysis)
2135
+ add (() => taskBackend.trackPackage (
2136
+ package,
2137
+ updateDependents: taskUpdateDependents,
2138
+ )),
2139
+ if (! skipExport)
2140
+ add (() => apiExporter.synchronizePackage (
2141
+ package,
2142
+ forceDelete: exportForceDelete,
2143
+ // TODO: implement and use [skipVersionsExport]
2144
+ )),
2145
+ ];
2146
+
2147
+ return (future: Future .wait (futures));
2148
+ }
0 commit comments