Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/calendar-client/src/dataManage/lunarmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ void LunarManager::queryLunarInfo(const QDate &startDate, const QDate &stopDate)
delete dbus;
return lunarInfoMap;
});
connect(w, &QFutureWatcher<QMap<QDate, CaHuangLiDayInfo>>::finished, this, [this, w]() {
m_lunarInfoMap = w->result();
qCDebug(ClientLogger) << "Lunar info query completed with" << m_lunarInfoMap.size() << "days";
connect(w, &QFutureWatcher<QMap<QDate, CaHuangLiDayInfo>>::finished, this, [this, w, startDate, stopDate]() {
auto result = w->result();
for (auto it = result.constBegin(); it != result.constEnd(); ++it) {
m_lunarInfoMap[it.key()] = it.value();
}
m_pendingQueries.remove(qMakePair(startDate, stopDate));
qCDebug(ClientLogger) << "Lunar info query completed, total cached:" << m_lunarInfoMap.size() << "days";
w->deleteLater();
emit lunarInfoReady();
});
Expand Down Expand Up @@ -191,14 +195,14 @@ void LunarManager::queryFestivalInfo(const QDate &startDate, const QDate &stopDa
delete dbus;
return festivallist;
});
connect(w, &QFutureWatcher<QVector<FestivalInfo>>::finished, this, [this, w]() {
connect(w, &QFutureWatcher<QVector<FestivalInfo>>::finished, this, [this, w, startDate, stopDate]() {
auto festivallist = w->result();
m_festivalDateMap.clear();
for (const FestivalInfo &info : festivallist) {
for (const HolidayInfo &h : info.listHoliday) {
m_festivalDateMap[h.date] = h.status;
}
}
m_pendingQueries.remove(qMakePair(startDate, stopDate));
qCDebug(ClientLogger) << "Festival date map updated with" << m_festivalDateMap.size() << "days";
w->deleteLater();
emit festivalInfoReady();
Expand Down Expand Up @@ -274,7 +278,7 @@ QMap<QDate, CaHuangLiDayInfo> LunarManager::getHuangLiDayMap(const QDate &startD
QMap<QDate, CaHuangLiDayInfo> lunarInfoMap;
auto iterator = m_lunarInfoMap.begin();
while(iterator != m_lunarInfoMap.end()) {
if (iterator.key() >= startDate || iterator.key() <= stopDate) {
if (iterator.key() >= startDate && iterator.key() <= stopDate) {
iterator.value();
lunarInfoMap[iterator.key()] = iterator.value();
}
Expand All @@ -297,7 +301,7 @@ QMap<QDate, int> LunarManager::getFestivalInfoDateMap(const QDate &startDate, co
QMap<QDate, int> festivalDateMap;
auto iterator = m_festivalDateMap.begin();
while(iterator != m_festivalDateMap.end()) {
if (iterator.key() >= startDate || iterator.key() <= stopDate) {
if (iterator.key() >= startDate && iterator.key() <= stopDate) {
iterator.value();
festivalDateMap[iterator.key()] = iterator.value();
}
Expand All @@ -321,6 +325,12 @@ void LunarManager::ensureLunarDataLoaded(const QDate &startDate, const QDate &en
return;
}

// Prevent re-entrant queries for the same range while DBus call is in flight
auto key = qMakePair(startDate, endDate);
if (m_pendingQueries.contains(key)) {
return;
}

// Check if this range (or a superset) has already been queried
for (const auto &range : m_queriedRanges) {
if (startDate >= range.first && endDate <= range.second) {
Expand All @@ -338,6 +348,7 @@ void LunarManager::ensureLunarDataLoaded(const QDate &startDate, const QDate &en
if (cachedDays < expectedDays) {
qCDebug(ClientLogger) << "Querying lunar data for range" << startDate.toString() << "to" << endDate.toString()
<< "expected:" << expectedDays << "cached:" << cachedDays;
m_pendingQueries.insert(key);
queryLunarInfo(startDate, endDate);
queryFestivalInfo(startDate, endDate);
}
Expand Down
1 change: 1 addition & 0 deletions src/calendar-client/src/dataManage/lunarmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public slots:
QMap<QDate, CaHuangLiDayInfo> m_lunarInfoMap; //缓存的农历数据
QMap<QDate, int> m_festivalDateMap; //缓存的节假日数据
QList<QPair<QDate, QDate>> m_queriedRanges; //已查询的日期范围缓存
QSet<QPair<QDate, QDate>> m_pendingQueries; //正在查询中的范围,防止重入

};
#define gLunarManager LunarManager::getInstace()
Expand Down
39 changes: 37 additions & 2 deletions src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dbusaccountmanagerrequest.h"
#include "commondef.h"

Check warning on line 6 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commondef.h" not found.

Check warning on line 6 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "commondef.h" not found.
#include "dcalendargeneralsettings.h"

Check warning on line 7 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dcalendargeneralsettings.h" not found.

Check warning on line 7 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "dcalendargeneralsettings.h" not found.
#include <QDBusInterface>

Check warning on line 8 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusReply>

Check warning on line 9 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusReply> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDBusReply> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 10 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in src/calendar-client/src/dbus/dbusaccountmanagerrequest.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DbusAccountManagerRequest::DbusAccountManagerRequest(QObject *parent)
: DbusRequestBase("/com/deepin/dataserver/Calendar/AccountManager", "com.deepin.dataserver.Calendar.AccountManager", QDBusConnection::sessionBus(), parent)
Expand Down Expand Up @@ -192,9 +193,43 @@

//错误处理
if (call->isError()) {
qCWarning(ClientLogger) << "DBus call error - Method:" << call->reply().member()
qCWarning(ClientLogger) << "DBus call error - Method:" << call->reply().member()
<< "Error:" << call->error().message();
ret = 1;
// Retry critical calls synchronously on failure
if (call->getmember() == "getAccountList") {
qCInfo(ClientLogger) << "Retrying getAccountList synchronously";
QDBusReply<QString> reply = callWithArgumentList(QDBus::Block, "getAccountList", QList<QVariant>());
if (reply.isValid()) {
DAccount::List accountList;
if (DAccount::fromJsonListString(accountList, reply.value())) {
emit signalGetAccountListFinish(accountList);
canCall = false;
}
}
if (canCall) ret = 1;
} else if (call->getmember() == "getCalendarGeneralSettings") {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
qCInfo(ClientLogger) << "Retrying getCalendarGeneralSettings synchronously";
QDBusReply<QString> reply = callWithArgumentList(QDBus::Block, "getCalendarGeneralSettings", QList<QVariant>());
if (reply.isValid()) {
DCalendarGeneralSettings::Ptr ptr;
ptr.reset(new DCalendarGeneralSettings());
if (DCalendarGeneralSettings::fromJsonString(ptr, reply.value())) {
emit signalGetGeneralSettingsFinish(ptr);
canCall = false;
}
}
if (canCall) ret = 1;
} else if (call->getmember() == "isSupportUid") {
qCInfo(ClientLogger) << "Retrying isSupportUid synchronously";
QDBusReply<bool> reply = callWithArgumentList(QDBus::Block, "isSupportUid", QList<QVariant>());
if (reply.isValid()) {
emit signalGetIsSupportUidFinish(reply.value());
canCall = false;
}
if (canCall) ret = 1;
} else {
ret = 1;
}
} else if (call->getmember() == "getAccountList") {
qCDebug(ClientLogger) << "Processing getAccountList response";
QDBusPendingReply<QString> reply = *call;
Expand Down
15 changes: 8 additions & 7 deletions src/calendar-client/src/widget/calendarmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,23 @@ void Calendarmainwindow::slotCurrentDateUpdate()
// qCDebug(ClientLogger) << "Calendarmainwindow::slotCurrentDateUpdate";
//获取当前时间
const QDateTime _currentDate = QDateTime::currentDateTime();
//设置当前时间
if (m_DayWindow) m_DayWindow->setCurrentDateTime(_currentDate);
//只对日视图更新当前时间(用于时间线绘制),仅当日视图可见时
if (m_DayWindow && m_stackWidget->currentIndex() == DDECalendar::CalendarDayWindow)
m_DayWindow->setCurrentDateTime(_currentDate);
//如果当前日期与动态图标日期不一样则重新生成动态图标
if (_currentDate.date() != CDynamicIcon::getInstance()->getDate()) {
qCDebug(ClientLogger) << "Updating dynamic icon date" << "new date:" << QDate::currentDate();
CDynamicIcon::getInstance()->setDate(QDate::currentDate());
CDynamicIcon::getInstance()->setIcon();
//更新视图数据显示
for (int i = 0; i < m_stackWidget->count(); ++i) {
CScheduleBaseWidget *widget = qobject_cast<CScheduleBaseWidget *>(m_stackWidget->widget(i));
if (widget) widget->updateData();
}
//更新当前可见视图数据显示
CScheduleBaseWidget *currentWidget = qobject_cast<CScheduleBaseWidget *>(m_stackWidget->currentWidget());
if (currentWidget) currentWidget->updateData();
//设置年视图年数据时间显示
if (m_yearwindow) m_yearwindow->setYearData();
//更新月视图当前周横线绘制
if (m_monthWindow) m_monthWindow->setCurrentDateTime(_currentDate);
//日期变化时也要更新日视图时间
if (m_DayWindow) m_DayWindow->setCurrentDateTime(_currentDate);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/calendar-client/src/widget/yearWidget/yearwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ void CYearWindow::updateShowLunar()
if (getShowLunar()) {
QDate yearStart(getSelectDate().year(), 1, 1);
QDate yearEnd(getSelectDate().year(), 12, 31);
gLunarManager->queryLunarInfo(yearStart, yearEnd);
gLunarManager->queryFestivalInfo(yearStart, yearEnd);
gLunarManager->ensureLunarDataLoaded(yearStart, yearEnd);
}

//获取农历信息
Expand Down
Loading