summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-12-22 18:34:27 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-12-22 18:34:27 +0300
commitb9b13c24e57da1ad7a039d88935b3873d23a56d1 (patch)
tree556dbbccbcdb8fb6e71abd5eb859cbb2d964aca1
parent496cd8776e8fcf49284717fa717e8bbe620bcc3f (diff)
fixes #4073 (NewStory: новые тормоза, и даже креш)
-rw-r--r--plugins/NewStory/src/history.h1
-rw-r--r--plugins/NewStory/src/history_array.cpp14
-rw-r--r--plugins/NewStory/src/history_array.h7
-rw-r--r--plugins/NewStory/src/history_control.cpp77
-rw-r--r--plugins/NewStory/src/history_control.h10
5 files changed, 43 insertions, 66 deletions
diff --git a/plugins/NewStory/src/history.h b/plugins/NewStory/src/history.h
index 7bcf223d7f..f71bab9fed 100644
--- a/plugins/NewStory/src/history.h
+++ b/plugins/NewStory/src/history.h
@@ -18,7 +18,6 @@ enum
UM_ADDEVENTFILTER,
UM_REMOVEEVENT,
UM_EDITEVENT,
- UM_MARKREAD,
UM_SELECTED,
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 8ffa8c3106..7fa979e204 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -369,9 +369,9 @@ void ItemData::getFontColor(int &fontId, int &colorId) const
}
}
-void ItemData::load(int flags)
+void ItemData::load(bool bLoadAlways)
{
- if (!(flags & LOAD_ALWAYS) && m_bLoaded)
+ if (!bLoadAlways && m_bLoaded)
return;
if (!fetch())
@@ -382,8 +382,7 @@ void ItemData::load(int flags)
switch (dbe.eventType) {
case EVENTTYPE_MESSAGE:
- if (!(flags & LOAD_BACK))
- markRead();
+ markRead();
__fallthrough;
case EVENTTYPE_STATUSCHANGE:
@@ -409,8 +408,7 @@ void ItemData::load(int flags)
buf.AppendFormat(TranslateT(" %u KB"), size < 1024 ? 1 : unsigned(blob.getSize() / 1024));
wtext = buf.Detach();
- if (!(flags & LOAD_BACK))
- markRead();
+ markRead();
break;
}
@@ -637,7 +635,7 @@ int HistoryArray::find(MEVENT hEvent)
return -1;
}
-ItemData* HistoryArray::get(int id, bool bLoad, bool bBack) const
+ItemData* HistoryArray::get(int id, bool bLoad) const
{
int pageNo = id / HIST_BLOCK_SIZE;
if (pageNo >= pages.getCount())
@@ -645,7 +643,7 @@ ItemData* HistoryArray::get(int id, bool bLoad, bool bBack) const
auto *p = &pages[pageNo].data[id % HIST_BLOCK_SIZE];
if (bLoad && !p->m_bLoaded)
- p->load((bBack) ? LOAD_BACK : 0);
+ p->load();
return p;
}
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index 37aca66fb3..29331d0235 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -10,9 +10,6 @@ enum
CMStringW TplFormatString(int tpl, MCONTACT hContact, ItemData *item);
-#define LOAD_ALWAYS 0x0001
-#define LOAD_BACK 0x0002
-
struct ItemData
{
MCONTACT hContact;
@@ -43,7 +40,7 @@ struct ItemData
bool fetch(void);
void fill(int tmpl);
- void load(int flags = 0);
+ void load(bool bLoad = false);
bool isLink(HWND, POINT pt, CMStringW *url = nullptr) const;
bool isLinkChar(HWND, int idx) const;
@@ -156,7 +153,7 @@ public:
hwndOwner = hwnd;
}
- ItemData* get(int id, bool bLoad = false, bool bBack = false) const;
+ ItemData* get(int id, bool bLoad = false) const;
ItemData* insert(int idx);
__forceinline int FindNext(int id, const Filter &filter) { return find(id, +1, filter); }
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index c9aa4509a6..c880bbd57a 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -57,13 +57,34 @@ void InitHotkeys()
NewstoryListData::NewstoryListData(HWND _1) :
m_hwnd(_1),
- redrawTimer(Miranda_GetSystemWindow(), (LPARAM)this)
+ loadTimer(Miranda_GetSystemWindow(), LPARAM(this)),
+ redrawTimer(Miranda_GetSystemWindow(), LPARAM(this)+1)
{
items.setOwner(_1);
bSortAscending = g_plugin.bSortAscending;
- redrawTimer.OnEvent = Callback(this, &NewstoryListData::OnTimer);
+ loadTimer.OnEvent = Callback(this, &NewstoryListData::onTimer_Load);
+ redrawTimer.OnEvent = Callback(this, &NewstoryListData::onTimer_Draw);
+}
+
+void NewstoryListData::onTimer_Draw(CTimer *pTimer)
+{
+ pTimer->Stop();
+
+ if (bWasAtBottom)
+ EnsureVisible(totalCount - 1);
+
+ InvalidateRect(m_hwnd, 0, FALSE);
+}
+
+void NewstoryListData::onTimer_Load(CTimer *pTimer)
+{
+ for (int i = 0; i < 100 && loadCount >= 0; i++)
+ LoadItem(loadCount--);
+
+ if (loadCount < 0)
+ pTimer->Stop();
}
void NewstoryListData::OnContextMenu(int index, POINT pt)
@@ -97,16 +118,6 @@ void NewstoryListData::OnResize(int newWidth, int newHeight)
InvalidateRect(m_hwnd, 0, FALSE);
}
-void NewstoryListData::OnTimer(CTimer *pTimer)
-{
- pTimer->Stop();
-
- if (bWasAtBottom)
- EnsureVisible(totalCount - 1);
-
- InvalidateRect(m_hwnd, 0, FALSE);
-}
-
void NewstoryListData::AddChatEvent(SESSION_INFO *si, const LOGINFO *lin)
{
ScheduleDraw();
@@ -116,41 +127,16 @@ void NewstoryListData::AddChatEvent(SESSION_INFO *si, const LOGINFO *lin)
/////////////////////////////////////////////////////////////////////////////////////////
-static void __cdecl sttLoadItems(void *param)
-{
- SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);
-
- auto *pData = (NewstoryListData *)param;
- for (int i = pData->totalCount-1; i >= 0; i--) {
- auto *pItem = pData->LoadItem(i, true);
- if (!pItem)
- break;
-
- switch (pItem->dbe.eventType) {
- case EVENTTYPE_FILE:
- if (!pItem->m_bOfflineFile)
- break;
- __fallthrough;
-
- case EVENTTYPE_MESSAGE:
- if (!(pItem->dbe.flags & DBEF_SENT) && !pItem->dbe.markedRead())
- PostMessage(pData->m_hwnd, UM_MARKREAD, WPARAM(pItem), 0);
- break;
- }
-
- if ((i % 100) == 0)
- Sleep(50);
- }
-}
-
void NewstoryListData::AddEvent(MCONTACT hContact, MEVENT hFirstEvent, int iCount)
{
ScheduleDraw();
items.addEvent(hContact, hFirstEvent, iCount);
totalCount = items.getCount();
- if (iCount == -1)
- mir_forkthread(sttLoadItems, this);
+ if (iCount == -1) {
+ loadCount = totalCount - 1;
+ loadTimer.Start(50);
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -569,13 +555,13 @@ void NewstoryListData::HitTotal(int yCurr, int yTotal)
FixScrollPosition();
}
-ItemData* NewstoryListData::LoadItem(int idx, bool bBack)
+ItemData* NewstoryListData::LoadItem(int idx)
{
if (totalCount == 0)
return nullptr;
mir_cslock lck(m_csItems);
- return (bSortAscending) ? items.get(idx, true, bBack) : items.get(totalCount - 1 - idx, true, bBack);
+ return (bSortAscending) ? items.get(idx, true) : items.get(totalCount - 1 - idx, true);
}
void NewstoryListData::OpenFolder()
@@ -1122,11 +1108,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
}
break;
- case UM_MARKREAD:
- if (auto *pItem = (ItemData *)wParam)
- pItem->markRead();
- break;
-
case WM_SIZE:
data->OnResize(LOWORD(lParam), HIWORD(lParam));
break;
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 619d6f01ce..658e351d9d 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -19,7 +19,7 @@ struct NewstoryListData : public MZeroedObject
int cachedWindowWidth = -1, cachedWindowHeight = -1;
int cachedMaxDrawnItem = -1;
int cachedScrollbarPos = -1, cachedScrollbarMax = -1;
- int totalCount;
+ int totalCount, loadCount = -1;
RECT rcLastPaint;
@@ -28,12 +28,14 @@ struct NewstoryListData : public MZeroedObject
HWND m_hwnd;
HWND hwndEditBox;
- CTimer redrawTimer;
+ CTimer redrawTimer, loadTimer;
CSrmmBaseDialog *pMsgDlg = nullptr;
void OnContextMenu(int index, POINT pt);
void OnResize(int newWidth, int newHeight);
- void OnTimer(CTimer *pTimer);
+
+ void onTimer_Draw(CTimer *pTimer);
+ void onTimer_Load(CTimer *pTimer);
void AddChatEvent(SESSION_INFO *si, const LOGINFO *lin);
void AddEvent(MCONTACT hContact, MEVENT hFirstEvent, int iCount);
@@ -67,7 +69,7 @@ struct NewstoryListData : public MZeroedObject
void HitTotal(int yCurr, int yTotal);
void LineUp();
void LineDown();
- ItemData* LoadItem(int idx, bool bBack = false);
+ ItemData* LoadItem(int idx);
void OpenFolder();
void PageUp();
void PageDown();