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:
1 parent
d09dec4706
commit
07b0232726
3 files changed
+91
-74
No files matched your search
@@ -56,10 +56,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].left = 81.1;
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.left = 81.1;
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to left.");
|
||||
@@ -90,10 +91,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].left = 480 - (shapes.items[i].width / 2);
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.left = 480 - (shape.width / 2);
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to center.");
|
||||
@@ -124,10 +126,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].left = 879.75 - shapes.items[i].width;
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.left = 879.75 - shape.width;
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to right.");
|
||||
@@ -158,10 +161,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].top = 136.75;
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.top = 136.75;
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to top.");
|
||||
@@ -192,10 +196,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].top = 321 - (shapes.items[i].height / 2);
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.top = 321 - (shape.height / 2);
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to middle.");
|
||||
@@ -226,10 +231,11 @@ export const AlignmentButtons: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through all select shapes and align them
|
||||
for (let i = 0; i < shapes.items.length; i++) {
|
||||
shapes.items[i].top = 505.25 - shapes.items[i].height;
|
||||
}
|
||||
// Set alignment for all shapes at once
|
||||
shapes.items.forEach(shape => {
|
||||
shape.top = 505.25 - shape.height;
|
||||
});
|
||||
// Single sync after all updates
|
||||
await context.sync();
|
||||
|
||||
setStatusMessage("Objects aligned to bottom.");
|
||||
|
||||
Reference in new issue
Block a user