Limit fetching Activities to 100 or max. 30 days old

Signed-off-by: Michael Schuster <michael@schuster.ms>
This commit is contained in:
Michael Schuster 2020-01-17 20:25:41 +01:00
parent 3ae55c2555
commit e2188b109a
No known key found for this signature in database
GPG key ID: 00819E3BF4177B28
2 changed files with 17 additions and 0 deletions

View file

@ -247,6 +247,9 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st
_currentlyFetching = false; _currentlyFetching = false;
QDateTime oldestDate = QDateTime::currentDateTime();
oldestDate = oldestDate.addDays(_maxActivitiesDays * -1);
foreach (auto activ, activities) { foreach (auto activ, activities) {
auto json = activ.toObject(); auto json = activ.toObject();
@ -271,6 +274,14 @@ void ActivityListModel::slotActivitiesReceived(const QJsonDocument &json, int st
list.append(a); list.append(a);
_currentItem = list.last()._id; _currentItem = list.last()._id;
_totalActivitiesFetched++;
if(_totalActivitiesFetched == _maxActivities ||
a._dateTime < oldestDate) {
_doneFetching = true;
break;
}
} }
_activityLists.append(list); _activityLists.append(list);
@ -432,6 +443,7 @@ void ActivityListModel::slotRefreshActivity()
_activityLists.clear(); _activityLists.clear();
_doneFetching = false; _doneFetching = false;
_currentItem = 0; _currentItem = 0;
_totalActivitiesFetched = 0;
if (canFetchActivities()) { if (canFetchActivities()) {
startFetchJob(); startFetchJob();
@ -448,5 +460,6 @@ void ActivityListModel::slotRemoveAccount()
_currentlyFetching = false; _currentlyFetching = false;
_doneFetching = false; _doneFetching = false;
_currentItem = 0; _currentItem = 0;
_totalActivitiesFetched = 0;
} }
} }

View file

@ -102,6 +102,10 @@ private:
bool _currentlyFetching = false; bool _currentlyFetching = false;
bool _doneFetching = false; bool _doneFetching = false;
int _currentItem = 0; int _currentItem = 0;
int _totalActivitiesFetched = 0;
int _maxActivities = 100;
int _maxActivitiesDays = 30;
}; };
} }