Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add check update interval against lastUpdate on startup (fix #1502) #1522

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
62 changes: 60 additions & 2 deletions src/application/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <QStatusBar>
#include <qzregexp.h>

#include <QMessageBox>

// ---------------------------------------------------------------------------
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
Expand Down Expand Up @@ -3081,6 +3083,13 @@ void MainWindow::slotUpdateFeed(int feedId, bool changed, int newCount, bool fin
isStartImportFeed_ = false;
}

//m_Db.save(feedId, "lastCheckForUpdate", QDateTime::currentDateTimeUtc());
QSqlQuery q;
q.prepare("UPDATE feeds SET lastCheckForUpdate = ? WHERE id == ?");
q.addBindValue(QDateTime::currentDateTimeUtc().toString(Qt::ISODate));
q.addBindValue(feedId);
q.exec();

if (!changed) {
emit signalNextUpdate(finish);
return;
Expand Down Expand Up @@ -4099,7 +4108,9 @@ void MainWindow::initUpdateFeeds()
}
}

q.exec("SELECT id, updateInterval, updateIntervalType FROM feeds WHERE xmlUrl != '' AND updateIntervalEnable == 1");
qint64 currentTimestamp = QDateTime::currentSecsSinceEpoch();
q.exec("SELECT id, updateInterval, updateIntervalType, lastCheckForUpdate FROM feeds WHERE xmlUrl != '' AND updateIntervalEnable == 1");
QSet<int> feedIdsWithUpdateScheduled;
while (q.next()) {
int updateInterval = q.value(1).toInt();
int updateIntervalType = q.value(2).toInt();
Expand All @@ -4109,7 +4120,23 @@ void MainWindow::initUpdateFeeds()
updateInterval = updateInterval*60*60;

updateFeedsIntervalSec_.insert(q.value(0).toInt(), updateInterval);
updateFeedsTimeCount_.insert(q.value(0).toInt(), 0);
int updateFeedsTimeCountInitialValue = 0;

//check feed specific update interval against lastCheckForUpdate. see if update interval has elapsed since lastCheckForUpdate while the application was closed
QString lastCheckForUpdate = q.value(3).toString();
if (lastCheckForUpdate.isEmpty()) {
lastCheckForUpdate = QDateTime::fromSecsSinceEpoch(1, Qt::UTC).toString(Qt::ISODate);
}
QDateTime lastCheckForUpdateDateTime = QDateTime::fromString(lastCheckForUpdate, Qt::ISODate);
if (lastCheckForUpdateDateTime.isValid()) {
lastCheckForUpdateDateTime.setTimeSpec(Qt::UTC);
qint64 lastCheckForUpdateTimestamp = lastCheckForUpdateDateTime.toSecsSinceEpoch();
if (currentTimestamp > (lastCheckForUpdateTimestamp + updateInterval)) {
updateFeedsTimeCountInitialValue = updateInterval + 1; //indirectly trigger update using existing infrastructure (to avoid refactor)
feedIdsWithUpdateScheduled.insert(q.value(0).toInt());
}
}
updateFeedsTimeCount_.insert(q.value(0).toInt(), updateFeedsTimeCountInitialValue);
}

int updateInterval = updateFeedsInterval_;
Expand All @@ -4119,6 +4146,30 @@ void MainWindow::initUpdateFeeds()
updateInterval = updateInterval*60*60;
updateIntervalSec_ = updateInterval;

//check global update interval against lastCheckForUpdate
q.exec("SELECT id, lastCheckForUpdate FROM feeds WHERE xmlUrl != ''");
while (q.next()) {
QString lastCheckForUpdate = q.value(1).toString();
if (lastCheckForUpdate.isEmpty()) {
lastCheckForUpdate = QDateTime::fromSecsSinceEpoch(1, Qt::UTC).toString(Qt::ISODate);
}
QDateTime lastCheckForUpdateDateTime = QDateTime::fromString(lastCheckForUpdate, Qt::ISODate);
if (lastCheckForUpdateDateTime.isValid()) {
lastCheckForUpdateDateTime.setTimeSpec(Qt::UTC);
qint64 lastCheckForUpdateTimestamp = lastCheckForUpdateDateTime.toSecsSinceEpoch();
if (updateFeedsEnable_ && (currentTimestamp > (lastCheckForUpdateTimestamp + updateIntervalSec_))) {
int feedId = q.value(0).toInt();
if (!feedIdsWithUpdateScheduled.contains(feedId)) {
//emit signalGetFeedTimer(feedId); //directly trigger update, unless we scheduled an indirect update a few lines up
QMetaObject::invokeMethod(this, [this, feedId] {
this->signalGetFeedTimer(feedId);
}, Qt::QueuedConnection);
QMessageBox::information(this, "asdf", "yay scheduling update feed global shiz");
}
}
}
}

updateFeedsTimer_ = new QTimer(this);
connect(updateFeedsTimer_, SIGNAL(timeout()),
this, SLOT(slotGetFeedsTimer()));
Expand Down Expand Up @@ -5407,6 +5458,13 @@ void MainWindow::showFeedPropertiesDlg()
Qt::ISODate);
properties.status.createdTime = dt.addSecs(nTimeShift);

#if 0
dt = QDateTime::fromString(
feedsModel_->dataField(index, "lastCheckForUpdate").toString(),
Qt::ISODate);
properties.status.lastCheckForUpdate = dt.addSecs(nTimeShift);
#endif

dt = QDateTime::fromString(
feedsModel_->dataField(index, "updated").toString(),
Qt::ISODate);
Expand Down
1 change: 1 addition & 0 deletions src/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const QString kCreateFeedsTableQuery(
// --- Status ---
"status text, " // last update result
"created text, " // feed creation timestamp
"lastCheckForUpdate text, " // last check for update timestamp
"updated text, " // last update timestamp
"lastDisplayed text, " // last display timestamp
"f_Expanded integer default 1, " // expand folder flag
Expand Down
1 change: 1 addition & 0 deletions src/feedpropertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct {
QString description; //!< Feed description
QDateTime createdTime; //!< Time when feed created
QDateTime lastDisplayed; //!< Last time that feed displayed
//QDateTime lastCheckForUpdate; //!< Time of feed last check for update
QDateTime lastUpdate; //!< Time of feed last update
QDateTime lastBuildDate;
int undeleteCount; //!< Number of all news
Expand Down