mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
Replace unbounded ap_kv MongoDB collection (169K docs, 49MB) with Redis: - Fedify KV store uses @fedify/redis RedisKvStore (native TTL support) - Plugin cache (fedidb, batch-refollow state, migration flags) uses new redis-cache.js utility with indiekit: key prefix - All controllers updated to remove kvCollection parameter passing - Addresses OOM kills caused by ap_kv growing ~14K entries/day
83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
/**
|
|
* Admin controllers for the batch re-follow system.
|
|
*
|
|
* Provides pause, resume, and status endpoints for managing the
|
|
* background batch processor from the admin UI.
|
|
*/
|
|
|
|
import {
|
|
pauseBatchRefollow,
|
|
resumeBatchRefollow,
|
|
getBatchRefollowStatus,
|
|
} from "../batch-refollow.js";
|
|
|
|
/**
|
|
* POST /admin/refollow/pause — pause the batch processor.
|
|
*
|
|
* @param {string} mountPath - Plugin mount path
|
|
* @param {object} plugin - Plugin instance (for federation/collections access)
|
|
* @returns {Function} Express route handler
|
|
*/
|
|
export function refollowPauseController(mountPath, plugin) {
|
|
return async (request, response, next) => {
|
|
try {
|
|
const { application } = request.app.locals;
|
|
const collections = {
|
|
ap_following: application.collections.get("ap_following"),
|
|
};
|
|
|
|
await pauseBatchRefollow(collections);
|
|
|
|
response.json({ ok: true, status: "paused" });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* POST /admin/refollow/resume — resume the batch processor.
|
|
*
|
|
* @param {string} mountPath - Plugin mount path
|
|
* @param {object} plugin - Plugin instance
|
|
* @returns {Function} Express route handler
|
|
*/
|
|
export function refollowResumeController(mountPath, plugin) {
|
|
return async (request, response, next) => {
|
|
try {
|
|
await resumeBatchRefollow({
|
|
federation: plugin._federation,
|
|
collections: plugin._collections,
|
|
handle: plugin.options.actor.handle,
|
|
publicationUrl: plugin._publicationUrl,
|
|
});
|
|
|
|
response.json({ ok: true, status: "running" });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* GET /admin/refollow/status — get current batch processor status.
|
|
*
|
|
* @param {string} mountPath - Plugin mount path
|
|
* @returns {Function} Express route handler
|
|
*/
|
|
export function refollowStatusController(mountPath) {
|
|
return async (request, response, next) => {
|
|
try {
|
|
const { application } = request.app.locals;
|
|
const collections = {
|
|
ap_following: application.collections.get("ap_following"),
|
|
};
|
|
|
|
const status = await getBatchRefollowStatus(collections);
|
|
response.json(status);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
}
|