0

SharePoint online でアプリを作成し、すべてのユーザーとそのプロパティのリストを取得します ( http://social.technet.microsoft.com/wiki/contents/articles/25074.sharepoint-online-working-with-people-search- and-user-profiles.aspx )。

アプリは正常に動作しますが、結果ページ (350 ユーザー) の読み込み時間が非常に長くなります (~15 秒)。

どうやら、主な待ち時間 - これはPOSTリクエストの送信とレスポンスの受信です (~10 秒)。

このアプリを最適化するにはどうすればよいですか?

'use strict';

(function ($) {

$(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
        SP.SOD.executeFunc('SP.UserProfiles.js', 'SP.UserProfiles', getAllUsers);
    });
});

var users = [];    
var userProfileProperties = [];
var userProperties = [];
var userPropertiesFor = [];
var searchTerm = '*';
var results;


function getAllUsers() {

    var clientContext = new SP.ClientContext.get_current();
    var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
    keywordQuery.set_queryText(searchTerm);        
    keywordQuery.set_sourceId("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
    keywordQuery.set_rowLimit(500);
    keywordQuery.set_trimDuplicates(false);

    var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
    results = searchExecutor.executeQuery(keywordQuery);
    clientContext.executeQueryAsync(onQuerySuccess, onQueryError);
}

function onQueryError(sender, args) {
    alert(args.get_message());
}


function onQuerySuccess() {        
    $.each(results.m_value.ResultTables[0].ResultRows, function () {
        users.push(this.AccountName);            
    });        
    fetchProfilePropertiesForUsers();
}

function fetchProfilePropertiesForUsers() {        
    var clientContext = new SP.ClientContext.get_current();
    var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
    var profilePropertyNames = ["PreferredName", "WorkEmail", "Department", "PictureURL", "AccountName"];

    for (var i = 0; i < users.length; i++) {
        var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(clientContext, users[i], profilePropertyNames);
        userProfileProperties[i] = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
    }

    clientContext.executeQueryAsync(onSuccess, onQueryError);


}



function onSuccess() {                

    var divUserProfiles = document.getElementById('divUserProfiles');
    var html = "<style type='text/css'> .floatL {float:left;margin:10px;} .floatR {padding-top:10px} .profile {padding:10px 10px;} .editProfile{margin-left:100px;}  div>img {height:72px;width:72px;} </style>";
    for (var i = 0; i < userProfileProperties.length; i++) {
        html += "<div class='profile'><div class='floatL'><img src='" + userProfileProperties[i][3] + "' href='#' /></div><div class='floatR'><h2><span><a href='' >" + userProfileProperties[i][0] + "</a></span></h2><span>Work Email : " + userProfileProperties[i][1] + "</span><br /><span>Department  : " + userProfileProperties[i][2] + "</span><br /></div></div><br />";
    }        

    divUserProfiles.innerHTML = html;

}

})(jQuery);
4

1 に答える 1