Skip to content

Commit c81de29

Browse files
committed
Add per-block caching when extracting rich-text values
1 parent 60d9dbc commit c81de29

File tree

1 file changed

+13
-1
lines changed
  • packages/core-data/src/footnotes

1 file changed

+13
-1
lines changed

packages/core-data/src/footnotes/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@ const { getRichTextValues } = unlock( blockEditorPrivateApis );
1212

1313
let oldFootnotes = {};
1414

15+
const cache = new WeakMap();
16+
17+
function getRichTextValuesCached( block ) {
18+
if ( ! cache.has( block ) ) {
19+
const values = getRichTextValues( [ block ] );
20+
cache.set( block, values );
21+
}
22+
return cache.get( block );
23+
}
24+
1525
export function updateFootnotesFromMeta( blocks, meta ) {
1626
const output = { blocks };
1727
if ( ! meta ) return output;
28+
1829
// If meta.footnotes is empty, it means the meta is not registered.
1930
if ( meta.footnotes === undefined ) return output;
2031

21-
const _content = getRichTextValues( blocks ).join( '' ) || '';
32+
const _content = blocks.map( getRichTextValuesCached ).join( '' );
33+
2234
const newOrder = [];
2335

2436
// This can be avoided when

0 commit comments

Comments
 (0)