如何处理大量的行以及海量的列数据?
按照我们的需求,我们已创建一个SharePoint站点集合和一个名为 “My List Data” 的SharePoint列表,该列表包含Title(单行文本)、Description(多行文本)和Company(选项)字段。
We also developed an SPFx project for customization and implemented the following code to retrieve data from this SharePoint list.
import { spfi, SPFI, SPFx } from '@pnp/sp';
import '@pnp/sp/items';
import '@pnp/sp/lists';
import '@pnp/sp/webs';
const sp: SPFI = getSP();
const listData = await sp.web.lists.getByTitle("My List Data").items.select("").top(5000);
// Also, we have tried to select only the necessary columns
// const listData = await sp.web.lists.getByTitle("My List Data").items.select("Id,Title,Description,Company").top(5000);
console.log("listData:", listData);
由于行数众多,以及Description(Multi-Line Text)字段中的数据量较大,这影响了整体性能。Description列包含重要数据,因此我们不能在对SharePoint列表API的调用中排除该列。
Could anyone suggest an efficient approach to handle a large number of rows and high volumes of column data?
解决方案
Even when using .select(), SharePoint may still internally process large fields like multi-line text (especially if they are part of the default view or indexed poorly). This impacts performance significantly.
使用 $select + $top +分页
限制每次请求的项数,并分批处理:
const items = await sp.web.lists.getByTitle("My List Data").items.select("Id", "Title") // only required fields.top(100)(); // batch size
然后使用分页:
let allItems: any[] = [];
let pagedItems = await sp.web.lists.getByTitle("My List Data").items.top(100)();
while (pagedItems.hasNext) {
allItems = allItems.concat(pagedItems.results);
pagedItems = await pagedItems.getNext();
}
console.log("allItems:", allItems);
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。