@3sln/trove 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -966,12 +966,28 @@ export function createRouter() {
966
966
  // Install: upload the raw package zip; grants via ?grants=files,storage. The server
967
967
  // re-parses + validates and gates on scope (admin for server indexers / shared
968
968
  // resources), then stores the blob (deduped by digest) + the install record.
969
- r.post('/api/plugins/install', ['plugins'], async ({ plugins, principal, req, query }) => {
969
+ r.post('/api/plugins/install', ['plugins', 'backgroundWork'], async ({ plugins, principal, req, query, backgroundWork }) => {
970
970
  requirePlugins(plugins);
971
971
  requirePrincipal(principal);
972
972
  const bytes = await readBytesCapped(req, plugins.maxPackageBytes || 32 * 1024 * 1024);
973
973
  const grants = query.grants ? String(query.grants).split(',').map((s) => s.trim()).filter(Boolean) : undefined;
974
- return { install: await plugins.install({ principal, bytes, grants }) };
974
+ const install = await plugins.install({ principal, bytes, grants });
975
+
976
+ // A new indexer only earns its keep over files that are ALREADY here, and re-reading
977
+ // them is not work an install request can finish — so it is scheduled, not awaited.
978
+ // Skipped when the deployment cannot run them: `indexersSkipped` says so, and a task
979
+ // that indexes nothing is worse than no task, because it reports success.
980
+ let backfill = null;
981
+ if (install.indexers?.length && !install.indexersSkipped) {
982
+ const { task } = await backgroundWork.beginBackfill({
983
+ indexerIds: install.indexers.map((i) => i.id),
984
+ reason: `Indexing existing files for ${install.pluginId}`,
985
+ });
986
+ backfill = task;
987
+ }
988
+ // The task rides back with the install so a client can watch it rather than
989
+ // discovering later that its drive is quietly re-indexing.
990
+ return { install, backfill };
975
991
  }, { cost: 'install' });
976
992
 
977
993
  // List this account's server-installed plugins (for cross-device sync).