From 27dcc9508096cc4096d732a521b630852c7b063b Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 11 九月 2025 15:48:55 +0800
Subject: [PATCH] 1.查询时多取一行,使最后一行总是能配对上

---
 SourceCode/Bond/Servo/CPageGlassList.cpp |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CPageGlassList.cpp b/SourceCode/Bond/Servo/CPageGlassList.cpp
index fdbdcd4..38d93d3 100644
--- a/SourceCode/Bond/Servo/CPageGlassList.cpp
+++ b/SourceCode/Bond/Servo/CPageGlassList.cpp
@@ -619,12 +619,42 @@
     }
 
     // ==================== 2) DB 褰撳墠椤碉紙涓ら樁娈垫瀯寤猴紝澶勭悊鍗曞悜 buddy锛� ====================
+    const int rawLimit = PAGE_SIZE + 1;
+    const int rawOffset = PAGE_SIZE * (m_nCurPage - 1);
 #if USE_FAKE_DB_DEMO
-    auto page = _make_page_fake(m_filters, PAGE_SIZE, PAGE_SIZE * (m_nCurPage - 1));
+    auto page = _make_page_fake(m_filters, rawLimit, rawOffset);
 #else
     auto& db = GlassLogDb::Instance();
-    auto page = db.queryPaged(m_filters, PAGE_SIZE, PAGE_SIZE * (m_nCurPage - 1));
+    auto pageFull = db.queryPaged(m_filters, rawLimit, rawOffset);
 #endif
+
+    // 濡傛灉澶氬嚭涓�鏉★紝鐪嬬湅瀹冩槸鍚︽槸鈥滄湰椤垫渶鍚庝竴鏉♀�濈殑 buddy
+    std::optional<decltype(pageFull.items)::value_type> lookahead; // 棰勮璁板綍锛堣嫢涓庢渶鍚庝竴鏉¢厤瀵癸級
+    auto iEquals = [](const std::string& a, const std::string& b) {
+#ifdef _WIN32
+        return _stricmp(a.c_str(), b.c_str()) == 0;
+#else
+        return strcasecmp(a.c_str(), b.c_str()) == 0;
+#endif
+    };
+
+    if (pageFull.items.size() == rawLimit) {
+        const auto& last = pageFull.items[PAGE_SIZE - 1];
+        const auto& extra = pageFull.items[PAGE_SIZE];
+
+        bool pair =
+            (!last.buddyId.empty() && iEquals(last.buddyId, extra.classId)) ||
+            (!extra.buddyId.empty() && iEquals(extra.buddyId, last.classId));
+
+        if (pair) {
+            lookahead = extra;           // 鎶婇璇讳繚瀛樹笅鏉ワ紝绋嶅悗琛ユ垚瀛愯
+        }
+        // 鏃犺鏄惁閰嶅锛屽垪琛ㄩ兘缂╁洖 PAGE_SIZE 鏉★紙棰勮涓嶇畻鍏ユ湰椤垫暟鎹泦锛�
+        pageFull.items.pop_back();
+    }
+
+    // 涔嬪悗姝e父鎸� page 鏋勫缓
+    auto& page = pageFull; // 涓轰簡澶嶇敤浣犲師鏈夊彉閲忓悕
 
     // 寤虹储寮曪細classId -> index
     std::unordered_map<std::string, size_t> idxById;
@@ -643,6 +673,8 @@
     // -------- Phase 1: 鍏堝鐞嗏�滄湁 buddyId 鐨勮褰曗�濓紙鑳介厤灏遍厤锛涘崟鍚戜篃閰嶏級 ----------
     for (size_t i = 0; i < page.items.size(); ++i) {
         const auto& r = page.items[i];
+        AfxMessageBox(r.pretty.c_str());
+        
         if (consumed.count(r.classId)) continue;
         if (r.buddyId.empty()) continue;
 

--
Gitblit v1.9.3