Discourse: remove recheckTopicsInCategories feature (#1928)

Previously this recheck had a usecase: give priority to categories
that are used as Initiative source of truth. This model was abandoned
and so the priority doesn't make much sense either.

Instead use cache clearing to guarantee recent data when you need it.
This commit is contained in:
Robin van Boven 2020-07-06 20:56:01 +02:00 committed by GitHub
parent e6c7ac2063
commit 1b7a522f22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 118 deletions

View File

@ -2,7 +2,7 @@
import * as Combo from "../../util/combo";
import type {TaskReporter} from "../../util/taskReporter";
import type {Discourse, CategoryId, Topic, TopicLatest} from "./fetch";
import type {Discourse, Topic, TopicLatest} from "./fetch";
import {MirrorRepository} from "./mirrorRepository";
export type MirrorOptions = {|
@ -10,17 +10,10 @@ export type MirrorOptions = {|
// We need to proactively check them. This sets the interval at which we
// should check.
+recheckCategoryDefinitionsAfterMs: number,
// When you're concerned about potentially missed edits,
// this option lets you recheck all existing topics in a
// given set of category IDs (where 1 is uncategorized).
// It does not propagate into subcategories.
+recheckTopicsInCategories: $ReadOnlyArray<CategoryId>,
|};
const optionsParserFields = {
recheckCategoryDefinitionsAfterMs: Combo.number,
recheckTopicsInCategories: Combo.array<number>(Combo.number),
};
export const optionsParser: Combo.Parser<MirrorOptions> = Combo.object(
optionsParserFields
@ -31,7 +24,6 @@ export const optionsShapeParser: Combo.Parser<
const defaultOptions: MirrorOptions = {
recheckCategoryDefinitionsAfterMs: 24 * 3600 * 1000, // 24h
recheckTopicsInCategories: [],
};
function sortTopicByBumpedMs(a: TopicLatest, b: TopicLatest): number {
@ -128,18 +120,12 @@ export class Mirror {
? await this._fetcher.categoryDefinitionTopicIds()
: [];
// Add specific-category topics when it's set in our options.
const selectCategoryTopics = this._repo.topicsInCategories(
this._options.recheckTopicsInCategories
);
// Note: order is important here.
// Initial load should happen in order of bump date,
// reloads at the end are ok to be in random order.
const topicLoadQueue = [
...bumpedTopics.map((t) => t.id),
...definitionTopicIds,
...selectCategoryTopics,
].filter(once);
for (const topicId of topicLoadQueue) {

View File

@ -355,7 +355,6 @@ describe("plugins/discourse/mirror", () => {
// Explicitly set all options, so we know what to expect in tests.
const options: MirrorOptions = {
recheckCategoryDefinitionsAfterMs: 3600000, // 1h
recheckTopicsInCategories: [],
};
const fetcher = new MockFetcher();
const db = new Database(":memory:");
@ -626,108 +625,6 @@ describe("plugins/discourse/mirror", () => {
expect(laterTopics).toEqual([topic1, topic2]);
});
it("mirrors respects recheckTopicsInCategories option", async () => {
const expectedCategoryId = 2;
const {mirror, fetcher, reporter, repo} = example({
recheckTopicsInCategories: [expectedCategoryId],
});
const cooked = "<p>New content, without bump</p>";
const [t1, t2, t3] = [
fetcher.addTopic(),
fetcher.addTopic(),
fetcher.addTopic(),
];
const c1 = fetcher.addCategory();
const t5 = fetcher.addTopic({categoryId: c1.categoryId});
const topicsCall = jest.spyOn(fetcher, "topicWithPosts");
await mirror.update(reporter);
const earlyT1Post = fetcher._post(t1.postId);
fetcher.editPost(t1.postId, {cooked});
fetcher.editPost(t5.postId, {cooked});
const earlyCalls = [...topicsCall.mock.calls];
topicsCall.mockClear();
await mirror.update(reporter);
const laterPosts = repo.posts();
// The initial load has strict order requirements.
expect(earlyCalls).toEqual([
// Found through their bump date.
[t1.topicId],
[t2.topicId],
[t3.topicId],
[t5.topicId],
// Found through category definitions.
[c1.topicId],
]);
// The update does not.
expect(topicsCall).toHaveBeenCalledTimes(2);
expect(topicsCall).toHaveBeenCalledWith(4);
expect(topicsCall).toHaveBeenCalledWith(5);
// Make sure the t5 post is updated, but t1 isn't.
expect(laterPosts).toEqual([
earlyT1Post,
fetcher._post(t2.postId),
fetcher._post(t3.postId),
fetcher._post(c1.postId),
fetcher._post(t5.postId),
]);
});
it("mirrors supports the uncategorized category in recheckTopicsInCategories option", async () => {
const {mirror, fetcher, reporter} = example({
recheckTopicsInCategories: [1],
});
const [t1, t2] = [fetcher.addTopic(), fetcher.addTopic()];
const topicsCall = jest.spyOn(fetcher, "topicWithPosts");
await mirror.update(reporter);
const earlyCalls = [...topicsCall.mock.calls];
topicsCall.mockClear();
await mirror.update(reporter);
// The initial load has strict order requirements.
expect(earlyCalls).toEqual([[t1.topicId], [t2.topicId]]);
// The update does not.
expect(topicsCall).toHaveBeenCalledTimes(2);
expect(topicsCall).toHaveBeenCalledWith(1);
expect(topicsCall).toHaveBeenCalledWith(2);
});
it("doesn't recheck a topic more than once", async () => {
const expectedCategoryId = 2;
const {mirror, fetcher, reporter} = example({
recheckTopicsInCategories: [expectedCategoryId],
});
const [t1, _unused_t2, _unused_t3] = [
fetcher.addTopic(),
fetcher.addTopic(),
fetcher.addTopic(),
];
const c1 = fetcher.addCategory();
const t5 = fetcher.addTopic({categoryId: c1.categoryId});
await mirror.update(reporter);
const topicsCall = jest.spyOn(fetcher, "topicWithPosts");
fetcher.addPost({topicId: t1.topicId});
fetcher.addPost({topicId: t5.topicId});
await mirror.update(reporter);
// #1 will be updated because of the new post bump.
// #4 will be updated because of the recheck of category.
// #5 will be updated because of the new post bump and recheck of category.
expect(topicsCall).toHaveBeenCalledTimes(3);
expect(topicsCall).toHaveBeenCalledWith(t1.topicId);
expect(topicsCall).toHaveBeenCalledWith(c1.topicId);
expect(topicsCall).toHaveBeenCalledWith(t5.topicId);
});
it("should not fetch existing topics when adding a new one on second `update`", async () => {
const {mirror, fetcher, reporter, repo} = example();
fetcher.addTopic();