Optimize performance by batching context.sync() calls
- GridGuidelineManager: Load all shape names upfront and apply operations in batches - AlignmentButtons: Replaced for loops with forEach and reduced sync calls - MatchProperties: Reorganized code to batch load operations and property assignments This optimization significantly reduces round-trips between JavaScript and the Office application, improving performance and responsiveness of the add-in. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -241,13 +241,17 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
shapes.load("items");
|
||||
await context.sync();
|
||||
|
||||
// Find shapes that are part of our grid
|
||||
// Load all shape names at once
|
||||
const allShapes = shapes.items;
|
||||
for (let i = 0; i < allShapes.length; i++) {
|
||||
allShapes[i].load("name");
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
// Find shapes that are part of our grid and mark them for deletion
|
||||
let removedCount = 0;
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
const shape = shapes.items[i];
|
||||
shape.load("name");
|
||||
await context.sync();
|
||||
|
||||
for (let i = 0; i < allShapes.length; i++) {
|
||||
const shape = allShapes[i];
|
||||
// Check if this shape is part of our grid
|
||||
if (shape.name && shape.name.startsWith(GRID_PREFIX)) {
|
||||
shape.delete();
|
||||
@@ -255,6 +259,7 @@ export const GridGuidelineManager: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Single sync after all deletions
|
||||
await context.sync();
|
||||
|
||||
if (showStatus) {
|
||||
|
||||
Reference in New Issue
Block a user