@@ -290,6 +290,10 @@ function D.Search(ui, nPage)
290290 -- 兼容传 raw 或 wrapper
291291 ui = X .UI (ui )
292292
293+ -- 防止并发搜索回调覆盖新结果
294+ D .nSearchToken = (tonumber (D .nSearchToken ) or 0 ) + 1
295+ local nToken = D .nSearchToken
296+
293297 nPage = tonumber (nPage ) or 1
294298 if nPage < 1 then
295299 nPage = 1
@@ -298,6 +302,52 @@ function D.Search(ui, nPage)
298302 local szSearch = X .TrimString (ui :Fetch (' WndEditBox_Search' ):Text () or ' ' )
299303 local dwMapID = D .dwMapID or 0
300304
305+ local aAllList = nil
306+ local tFeedRecord = nil
307+ local nPending = 0
308+ local function fnToRecord (tInfo )
309+ if not X .IsTable (tInfo ) then
310+ return nil
311+ end
312+ return {
313+ id = tInfo .id ,
314+ key = tInfo .key ,
315+ szName = tInfo .name ,
316+ szAuthor = tInfo .author ,
317+ dwUpdateTime = tInfo .update ,
318+ szDataURL = tInfo .data_url ,
319+ szAboutURL = tInfo .about ,
320+ tRaw = tInfo ,
321+ }
322+ end
323+ local function fnFinalize ()
324+ if nToken ~= D .nSearchToken then
325+ return
326+ end
327+ if nPending > 0 then
328+ return
329+ end
330+
331+ local aDataSource = {}
332+ local nFeedID = nil
333+ if X .IsTable (tFeedRecord ) and tFeedRecord .id then
334+ nFeedID = tFeedRecord .id
335+ table.insert (aDataSource , tFeedRecord )
336+ end
337+ for _ , rec in ipairs (aAllList or {}) do
338+ if not (nFeedID and rec and rec .id == nFeedID ) then
339+ table.insert (aDataSource , rec )
340+ end
341+ end
342+ ui :Fetch (' WndTable_List' ):DataSource (aDataSource )
343+ end
344+ local function fnDoneOne ()
345+ nPending = nPending - 1
346+ fnFinalize ()
347+ end
348+
349+ -- 1) 排行榜列表
350+ nPending = nPending + 1
301351 X .Ajax ({
302352 url = MY_RSS .PULL_BASE_URL .. ' /api/addon/common-monitor/subscribe/all' ,
303353 data = {
@@ -310,35 +360,71 @@ function D.Search(ui, nPage)
310360 pageSize = 100 ,
311361 },
312362 success = function (szHTML )
363+ if nToken ~= D .nSearchToken then
364+ return
365+ end
313366 local res = X .DecodeJSON (szHTML )
314367 if not X .IsTable (res ) or not X .IsTable (res .data ) then
315368 X .OutputAnnounceMessage (_L [' Fetch repo meta list failed.' ])
316- ui :Fetch (' WndTable_List' ):DataSource ({})
369+ aAllList = {}
370+ fnDoneOne ()
317371 return
318372 end
319- local aDataSource = {}
373+ local a = {}
320374 for _ , info in ipairs (res .data ) do
321- table.insert (aDataSource , {
322- id = info .id ,
323- key = info .key ,
324- szName = info .name ,
325- szAuthor = info .author ,
326- dwUpdateTime = info .update ,
327- szDataURL = info .data_url ,
328- szAboutURL = info .about ,
329- __raw = info ,
330- })
375+ table.insert (a , fnToRecord (info ))
331376 end
332- ui :Fetch (' WndTable_List' ):DataSource (aDataSource )
377+ aAllList = a
378+ fnDoneOne ()
333379 end ,
334380 error = function (html , status )
381+ if nToken ~= D .nSearchToken then
382+ return
383+ end
335384 --[[ #DEBUG BEGIN]]
336385 X .OutputDebugMessage (_L [MODULE_NAME ], ' ERROR Fetch list: ' .. X .EncodeLUAData (status ) .. ' \n ' .. (X .ConvertToANSI (html ) or ' ' ), X .DEBUG_LEVEL .WARNING )
337386 --[[ #DEBUG END]]
338387 X .OutputAnnounceMessage (_L [' Fetch repo meta list failed.' ])
339- ui :Fetch (' WndTable_List' ):DataSource ({})
388+ aAllList = {}
389+ fnDoneOne ()
340390 end ,
341391 })
392+
393+ -- 2) 精准匹配(不在排行榜也能查)
394+ if not X .IsEmpty (szSearch ) then
395+ nPending = nPending + 1
396+ X .Ajax ({
397+ url = MY_RSS .PULL_BASE_URL .. ' /api/addon/common-monitor/subscribe/feed' ,
398+ data = {
399+ l = X .ENVIRONMENT .GAME_LANG ,
400+ L = X .ENVIRONMENT .GAME_EDITION ,
401+ T = 3 ,
402+ key = szSearch ,
403+ },
404+ success = function (szHTML )
405+ if nToken ~= D .nSearchToken then
406+ return
407+ end
408+ local res = X .DecodeJSON (szHTML )
409+ -- 不存在:{"code":404,"msg":"数据不存在"}
410+ if X .IsTable (res ) and res .id then
411+ tFeedRecord = fnToRecord (res )
412+ else
413+ tFeedRecord = nil
414+ end
415+ fnDoneOne ()
416+ end ,
417+ error = function (szHtml , szStatus )
418+ if nToken ~= D .nSearchToken then
419+ return
420+ end
421+ tFeedRecord = nil
422+ fnDoneOne ()
423+ end ,
424+ })
425+ end
426+
427+ fnFinalize ()
342428end
343429
344430function D .OnItemLButtonClick ()
0 commit comments