1

我们已经成功使用Core 5 文件管理器实用程序有一段时间了,但是一旦我们的目录开始积累 100 张图像,它就开始变慢,这对我们的 IE 用户来说非常严重。我现在正在尝试破解延迟加载,但非常不成功。

这是有问题的块:

// Retrieve the data and generate the markup.
$.getJSON(fileConnector + '?path=' + path + '&mode=getfolder&getsizes=false&showThumbs=' + showThumbs, function(data){      
    var result = '';

    if(data){
        if(data['Code'] && data['Code'] != 0)
        {
            result = "<div style='text-align:center;color:red;'>An error occured:<br \/>" + data['Error'] + "<\/div>";
            // $.prompt(data['Error']);
        } else
        {
            var key = '';
            if($('#fileinfo').data('view') == 'grid'){
                result += '<ul id="contents" class="grid">';

                for(key in data){
                    var props = data[key]['Properties'];
                    if (props)
                    {
                        var scaledWidth = 64;
                        var actualWidth = props['Width'];
                        if(actualWidth > 1 && actualWidth < scaledWidth) scaledWidth = actualWidth;

                        result += '<li class="' + (data[key]["File Type"] == 'dir' ? 'directory':'file') + '">'+
                         '<div class="clip"><img src="' + data[key]['Preview'] + '" width="' + scaledWidth + '" alt="' + data[key]['VisiblePath'] + '" /></div><p>' + data[key]['Filename'] + '</p>';
                        if(props['Width'] && props['Width'] != '') result += '<span class="meta dimensions">' + props['Width'] + 'x' + props['Height'] + '</span>';
                        if(props['Size'] && props['Size'] != '') result += '<span class="meta size">' + props['Size'] + '</span>';
                        if(props['Date Created'] && props['Date Created'] != '') result += '<span class="meta created">' + props['Date Created'] + '</span>';
                        if(props['Date Modified'] && props['Date Modified'] != '') result += '<span class="meta modified">' + props['Date Modified'] + '</span>';
                        result += '</li>';
                    }
                }
                result += '</ul>';
                if (key=='')
                {
                    result = '<div style="margin-top:40px;text-align:center;"><em>No files found</em></div>';
                }
            } else {
                result += '<table id="contents" class="list">';
                result += '<thead><tr><th class="headerSortDown"><span>Name</span></th><th><span>Dimensions</span></th><th><span>Size</span></th><th><span>Modified</span></th></tr></thead>';
                result += '<tbody>';

                for(key in data){
                    var path = data[key]['VisiblePath'];
                    var props = data[key]['Properties'];
                    if (props)
                    {
                        result += '<tr class="' + (data[key]["File Type"] == 'dir' ? 'directory':'file') + '">';
                        result += '<td title="' + path + '">' + data[key]['Filename'] + '</td>';

                        if(props['Width'] && props['Width'] != ''){
                            result += ('<td>' + props['Width'] + 'x' + props['Height'] + '</td>');
                        } else {
                            result += '<td></td>';
                        }

                        if(props['Size'] && props['Size'] != ''){
                            result += '<td><abbr title="' + props['Size'] + '">' + formatBytes(props['Size']) + '</abbr></td>';
                        } else {
                            result += '<td></td>';
                        }

                        if(props['Date Modified'] && props['Date Modified'] != ''){
                            result += '<td>' + props['Date Modified'] + '</td>';
                        } else {
                            result += '<td></td>';
                        }

                        result += '</tr>';
                    }
                }
                if (key=='')
                {
                    result += '<tr><td colspan="4" style="text-align:center"><em>No files found</em></td></tr>';
                }

                result += '</tbody>';
                result += '</table>';
            }
        }
    } else {
        result += '<h1>Could not retrieve folder contents.</h1>';
    }

    // Add the new markup to the DOM.
    $('#fileinfo').html(result);

json 请求命中一个coldfusion 函数,该函数使用cfdirectory 标记构建返回给调用者的数据结构

<cffunction name="_getDirectoryInfo" returntype="array" access="private">
    <cfargument name="path" type="string" required="yes" />
    <cfargument name="getsizes" type="boolean" required="yes" />
    <cfargument name="filter" type="string" required="no" default="" />
    <cfset var dirlist_qry = "" />
    <cfset var data_arr = arrayNew(1) />
    <cfset var currData_struct = "" />
    <cfset var imageData_struct = "" />
    <cfset var dirPath = (arguments.path) />
    <cfset var webDirPath = _getWebPath(dirPath) />
    <cfset var displayWebPath = _getWebPath(path=dirPath, includeUploadRoot=false) />

    <cfif not DirectoryExists(dirPath)>
        <cfdirectory action="create" directory="#dirPath#"> 
        <!--- no longer required, we will auto create the directory
        <cfset returnError(translate('DIRECTORY_NOT_EXIST', dirPath)) />
        --->
    </cfif>

    <cftry>
        <cfdirectory action="list" directory="#dirPath#" name="dirlist_qry" sort="type,name" filter="#arguments.filter#" />
        <cfcatch>
            <cfset returnError(translate('UNABLE_TO_OPEN_DIRECTORY', arguments.path, cfcatch.message & " - " & cfcatch.detail)) />
        </cfcatch>
    </cftry>

    <cfloop query="dirlist_qry"><cfif find('.', dirlist_qry.name) neq 1>
        <cfset currData_struct = structNew() />
        <cfset arrayAppend(data_arr, currData_struct) />

        <cfset structInsert(currData_struct, "Filename", dirlist_qry.name) />
        <cfset structInsert(currData_struct, "Error", "") />
        <cfset structInsert(currData_struct, "Code", 0) />
        <cfset structInsert(currData_struct, "Properties", structNew()) />
            <cfset structInsert(currData_struct.Properties, "Date Created", "") />
            <cfset structInsert(currData_struct.Properties, "Date Modified", "#lsdateformat(dateLastModified, 'medium')# #timeformat(dateLastModified, 'HH:mm:ss')#") />
            <cfset structInsert(currData_struct.Properties, "Height", "") />
            <cfset structInsert(currData_struct.Properties, "Width", "") />
        <cfif dirlist_qry.type eq "DIR">
            <cfset structInsert(currData_struct, "Path", webDirPath & dirlist_qry.name & "/") />
            <cfset structInsert(currData_struct, "VisiblePath", displayWebPath & dirlist_qry.name & "/") />
            <cfset structInsert(currData_struct, "File Type", "dir") />
            <cfset structInsert(currData_struct, "Preview", request.directoryIcon) />
            <cfset structInsert(currData_struct.Properties, "Size", "") />
        <cfelse>
            <cfset structInsert(currData_struct, "Path", webDirPath & dirlist_qry.name) />
            <cfset structInsert(currData_struct, "VisiblePath", displayWebPath & dirlist_qry.name) />
            <cfset structInsert(currData_struct, "File Type", lCase(listlast(dirlist_qry.name, '.'))) />
            <cfset structInsert(currData_struct.Properties, "Size", dirlist_qry.size) />
            <cfif _isImage(dirlist_qry.name)>
                <cfset structInsert(currData_struct, "Preview", webDirPath & dirlist_qry.name) />
                <cfif arguments.getsizes>
                    <cfset imageData_struct = _getImageInfo(dirlist_qry.directory & variables.separator & dirlist_qry.name) />
                    <cfset structInsert(currData_struct.Properties, "Height", imageData_struct.height, true) />
                    <cfset structInsert(currData_struct.Properties, "Width", imageData_struct.width, true) />
                </cfif>
            <cfelse>
                <cfset structInsert(currData_struct, "Preview", request.defaultIcon) />
            </cfif>
        </cfif>
    </cfif></cfloop>

    <cfreturn data_arr />
</cffunction>

经过广泛的研究,我找不到一种方法来设置开始/结束呼叫而不会导致更慢。我知道我不能成为唯一处理过这个问题的人,所以我想发布这个想法。我尝试的每个分页插件都无法正常工作,因为 core5 是如何设置的,即使这样,cfdi​​rectory 结构过程也可能需要很长时间。祝大家节日快乐。

4

1 回答 1

0

您的文件是否存储在 Windows 操作系统中?如果是这样,您是嵌套目录还是所有图像都存储在中央目录中?我发现当它只是一个包含所有文件的单独目录时,速度会随着时间的推移而蔓延。

以基于日期的约定存储文件,例如。/年月日

于 2012-12-09T02:12:34.347 回答