Feature/worker threads generation (#43)
* Add worker threads architecture plan for blog generation * fix: tries to optimize rendering, still slow * feat: moved site rendering into web worker * fix: calendar grabs from central data source for calendar * fix: feeds now use blog language content and not canonical content --------- Co-authored-by: hugo <hugoms@me.com>
This commit is contained in:
@@ -75,4 +75,65 @@ describe('GenerationPostSnapshotService', () => {
|
||||
expect(result.publishedPosts.map((post) => post.id).sort()).toEqual(['article', 'page']);
|
||||
expect(result.publishedListPosts.map((post) => post.id)).toEqual(['article']);
|
||||
});
|
||||
|
||||
it('uses getPublishedVersionsBulk when available for efficient loading', async () => {
|
||||
const published = makePost({ id: 'pub-1', status: 'published', categories: ['news'] });
|
||||
const draft = makePost({ id: 'draft-1', status: 'draft', categories: ['news'] });
|
||||
const pubSnapshot = makePost({ id: 'pub-1', status: 'published', categories: ['news'], title: 'Snapshot Title' });
|
||||
const draftSnapshot = makePost({ id: 'draft-1', status: 'published', categories: ['news'] });
|
||||
|
||||
const engine = makeEngine([published, draft]);
|
||||
let individualCallCount = 0;
|
||||
engine.getPublishedVersion = async () => {
|
||||
individualCallCount++;
|
||||
return null;
|
||||
};
|
||||
engine.getPublishedVersionsBulk = async (ids: string[]) => {
|
||||
const map = new Map<string, PostData>();
|
||||
if (ids.includes('pub-1')) map.set('pub-1', pubSnapshot);
|
||||
if (ids.includes('draft-1')) map.set('draft-1', draftSnapshot);
|
||||
return map;
|
||||
};
|
||||
|
||||
const result = await loadPublishedGenerationSets(engine, []);
|
||||
|
||||
expect(individualCallCount).toBe(0);
|
||||
expect(result.publishedPosts).toHaveLength(2);
|
||||
expect(result.publishedPosts.find(p => p.id === 'pub-1')?.title).toBe('Snapshot Title');
|
||||
});
|
||||
|
||||
it('uses bulk loading with list-excluded categories filtered in memory', async () => {
|
||||
const article = makePost({ id: 'article', status: 'published', categories: ['article'] });
|
||||
const page = makePost({ id: 'page', status: 'published', categories: ['page'] });
|
||||
const articleSnapshot = makePost({ id: 'article', status: 'published', categories: ['article'], title: 'Article Snap' });
|
||||
const pageSnapshot = makePost({ id: 'page', status: 'published', categories: ['page'], title: 'Page Snap' });
|
||||
|
||||
const engine = makeEngine([article, page]);
|
||||
engine.getPublishedVersionsBulk = async (ids: string[]) => {
|
||||
const map = new Map<string, PostData>();
|
||||
if (ids.includes('article')) map.set('article', articleSnapshot);
|
||||
if (ids.includes('page')) map.set('page', pageSnapshot);
|
||||
return map;
|
||||
};
|
||||
|
||||
const result = await loadPublishedGenerationSets(engine, ['page']);
|
||||
|
||||
expect(result.publishedPosts.map(p => p.id).sort()).toEqual(['article', 'page']);
|
||||
expect(result.publishedListPosts.map(p => p.id)).toEqual(['article']);
|
||||
});
|
||||
|
||||
it('only calls getPostsFiltered twice (published + draft), not four times', async () => {
|
||||
const post = makePost({ id: 'p1', status: 'published' });
|
||||
const engine = makeEngine([post]);
|
||||
let filterCallCount = 0;
|
||||
const originalGetPostsFiltered = engine.getPostsFiltered;
|
||||
engine.getPostsFiltered = async (filter) => {
|
||||
filterCallCount++;
|
||||
return originalGetPostsFiltered(filter);
|
||||
};
|
||||
|
||||
await loadPublishedGenerationSets(engine, ['some-category']);
|
||||
|
||||
expect(filterCallCount).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user