mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* perf: Use FOR NO KEY UPDATE where locked rows are only updated Rows that other tables reference by foreign key are now locked with FOR NO KEY UPDATE when the transaction only updates or soft-deletes them, so concurrent inserts that reference the row are not blocked. * test: Collaborative save does not wait for foreign key inserts
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Integration } from "@server/models";
|
|
import { sequelize } from "@server/storage/database";
|
|
import { Hook, PluginManager } from "@server/utils/PluginManager";
|
|
import { BaseTask } from "./base/BaseTask";
|
|
|
|
type Props = {
|
|
integrationId: string;
|
|
};
|
|
|
|
export default class CacheIssueSourcesTask extends BaseTask<Props> {
|
|
protected jobId({ integrationId }: Props) {
|
|
return `cache-issue-sources:${integrationId}`;
|
|
}
|
|
|
|
async perform({ integrationId }: Props) {
|
|
const integration = await Integration.findByPk(integrationId);
|
|
if (!integration) {
|
|
return;
|
|
}
|
|
|
|
const plugins = PluginManager.getHooks(Hook.IssueProvider);
|
|
const plugin = plugins.find((p) => p.value.service === integration.service);
|
|
if (!plugin) {
|
|
return;
|
|
}
|
|
|
|
const sources = await plugin.value.fetchSources(integration);
|
|
|
|
await sequelize.transaction(async (transaction) => {
|
|
await integration.reload({
|
|
transaction,
|
|
lock: transaction.LOCK.NO_KEY_UPDATE,
|
|
});
|
|
integration.issueSources = sources;
|
|
await integration.save({ transaction });
|
|
});
|
|
}
|
|
}
|