@@ -381,7 +381,11 @@ class PackageBackend {
381381 return true ;
382382 });
383383 if (updated) {
384- await purgePackageCache (package);
384+ triggerPackagePostUpdates (
385+ package,
386+ skipTask: true ,
387+ skipExport: true ,
388+ );
385389 }
386390 return updated;
387391 }
@@ -480,9 +484,7 @@ class PackageBackend {
480484 options: optionsChanges,
481485 ));
482486 });
483- await purgePackageCache (package);
484- await taskBackend.trackPackage (package);
485- await apiExporter.synchronizePackage (package);
487+ triggerPackagePostUpdates (package, skipVersionsExport: true );
486488 }
487489
488490 /// Updates [options] on [package] /[version] , assuming the current user
@@ -520,10 +522,9 @@ class PackageBackend {
520522 authenticatedUser, tx, p, pv, options.isRetracted! );
521523 }
522524 });
523- await purgePackageCache (package);
524525 await purgeScorecardData (package, version,
525526 isLatest: pkg.latestVersion == version);
526- await apiExporter. synchronizePackage (package);
527+ triggerPackagePostUpdates (package);
527528 }
528529
529530 /// Verifies an update to the credential-less publishing settings and
@@ -780,15 +781,18 @@ class PackageBackend {
780781 return _asPackagePublisherInfo (package);
781782 });
782783 await purgePublisherCache (publisherId: request.publisherId);
783- await purgePackageCache (packageName);
784784
785785 if (email != null ) {
786786 await emailBackend.trySendOutgoingEmail (email! );
787787 }
788788 if (currentPublisherId != null ) {
789789 await purgePublisherCache (publisherId: currentPublisherId);
790790 }
791- await apiExporter.synchronizePackage (packageName);
791+ triggerPackagePostUpdates (
792+ packageName,
793+ skipTask: true ,
794+ skipVersionsExport: true ,
795+ );
792796 return rs;
793797 }
794798
@@ -1299,7 +1303,7 @@ class PackageBackend {
12991303 sw.reset ();
13001304
13011305 _logger.info ('Invalidating cache for package ${newVersion .package }.' );
1302- await purgePackageCache (newVersion.package);
1306+ triggerPackagePostUpdates (newVersion.package, taskUpdateDependents : true );
13031307
13041308 // Let's not block the upload response on these post-upload tasks.
13051309 // The operations should either be non-critical, or should be retried
@@ -1324,12 +1328,10 @@ class PackageBackend {
13241328 await Future .wait ([
13251329 if (activeConfiguration.isPublishedEmailNotificationEnabled)
13261330 emailBackend.trySendOutgoingEmail (outgoingEmail),
1327- taskBackend.trackPackage (newVersion.package, updateDependents: true ),
1328- apiExporter.synchronizePackage (newVersion.package),
13291331 apiExporter.synchronizeAllPackagesAtomFeed (),
1332+ tarballStorage.updateContentDispositionOnPublicBucket (
1333+ newVersion.package, newVersion.version! ),
13301334 ]);
1331- await tarballStorage.updateContentDispositionOnPublicBucket (
1332- newVersion.package, newVersion.version! );
13331335 } catch (e, st) {
13341336 final v = newVersion.qualifiedVersionKey;
13351337 _logger.severe ('Error post-processing package upload $v ' , e, st);
@@ -1581,7 +1583,7 @@ class PackageBackend {
15811583 package: packageName,
15821584 ));
15831585 });
1584- await purgePackageCache (packageName);
1586+ triggerPackagePostUpdates (packageName, skipTask : true , skipExport : true );
15851587 }
15861588
15871589 Future <void > _validatePackageUploader (
@@ -1657,7 +1659,7 @@ class PackageBackend {
16571659 uploaderUser: uploader,
16581660 ));
16591661 });
1660- await purgePackageCache (packageName);
1662+ triggerPackagePostUpdates (packageName, skipTask : true , skipExport : true );
16611663 return api.SuccessMessage (
16621664 success: api.Message (
16631665 message:
@@ -2096,3 +2098,49 @@ class _VersionTransactionDataAcccess {
20962098 return await _tx.query <PackageVersion >(pkgKey).run ().toList ();
20972099 }
20982100}
2101+
2102+ /// Triggers post-update event processing after a [Package] object is part of
2103+ /// a transaction.
2104+ ///
2105+ /// Returns a record with an optionally awaitable [Future] in case the caller needs
2106+ /// wait the updates before yielding its response.
2107+ ({Future future}) triggerPackagePostUpdates (
2108+ String package, {
2109+ /// Skip trigger a new analysis on the package.
2110+ bool skipTask = false ,
2111+
2112+ /// Skip triggering a new export to the CDN bucket.
2113+ bool skipExport = false ,
2114+
2115+ /// Skip only the version-related exports to the CDN bucket, keeps the
2116+ /// package-related operations.
2117+ /// TODO: implement this in API exporter.
2118+ bool skipVersionsExport = false ,
2119+
2120+ /// Pass the force-deletion flag to the package export operation.
2121+ bool exportForceDelete = false ,
2122+
2123+ /// Pass the update-dependents flag to the task update operation.
2124+ bool taskUpdateDependents = false ,
2125+ }) {
2126+ Future add (Future Function () fn) {
2127+ return asyncQueue.addAsyncFn (fn).future;
2128+ }
2129+
2130+ final futures = [
2131+ add (() => purgePackageCache (package)),
2132+ if (! skipTask)
2133+ add (() => taskBackend.trackPackage (
2134+ package,
2135+ updateDependents: taskUpdateDependents,
2136+ )),
2137+ if (! skipExport)
2138+ add (() => apiExporter.synchronizePackage (
2139+ package,
2140+ forceDelete: exportForceDelete,
2141+ // TODO: implement and use [skipVersionsExport]
2142+ )),
2143+ ];
2144+
2145+ return (future: Future .wait (futures));
2146+ }
0 commit comments