lib/model, lib/stats: Keep track of folder's last scan time (ref #3143)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3250
LGTM: calmh, AudriusButkevicius
This commit is contained in:
Majed Abdulaziz 2016-06-02 19:26:52 +00:00 committed by Audrius Butkevicius
parent 16063933d1
commit 48245effdf
4 changed files with 32 additions and 1 deletions

View File

@ -360,6 +360,13 @@
<th><span class="fa fa-fw fa-share-alt"></span>&nbsp;<span translate>Shared With</span></th>
<td class="text-right">{{sharesFolder(folder)}}</td>
</tr>
<tr>
<th><span class="fa fa-fw fa-clock-o"></span>&nbsp;<span translate>Last Scan</span></th>
<td translate ng-if="folderStats[folder.id].lastScanDays >= 365" class="text-right">Never</td>
<td ng-if="folderStats[folder.id].lastScanDays < 365" class="text-right">
<span>{{folderStats[folder.id].lastScan | date:'yyyy-MM-dd HH:mm:ss'}}</span>
</td>
</tr>
<tr ng-if="folder.type != 'readonly' && folderStats[folder.id].lastFile && folderStats[folder.id].lastFile.filename">
<th><span class="fa fa-fw fa-exchange"></span>&nbsp;<span translate>Last File Received</span></th>
<td class="text-right">

View File

@ -171,6 +171,12 @@ angular.module('syncthing.core')
if (data.to === 'scanning') {
delete $scope.scanProgress[data.folder];
}
// If a folder finished scanning, then refresh folder stats
// to update last scan time.
if(data.from === 'scanning' && data.to === 'idle') {
refreshFolderStats();
}
}
});
@ -585,6 +591,9 @@ angular.module('syncthing.core')
if ($scope.folderStats[folder].lastFile) {
$scope.folderStats[folder].lastFile.at = new Date($scope.folderStats[folder].lastFile.at);
}
$scope.folderStats[folder].lastScan = new Date($scope.folderStats[folder].lastScan);
$scope.folderStats[folder].lastScanDays = (new Date() - $scope.folderStats[folder].lastScan) / 1000 / 86400;
}
console.log("refreshfolderStats", data);
}).error($scope.emitHTTPError);

View File

@ -1602,6 +1602,7 @@ func (m *Model) internalScanFolderSubdirs(folder string, subs []string) error {
m.updateLocalsFromScanning(folder, batch)
}
m.folderStatRef(folder).ScanCompleted()
runner.setState(FolderIdle)
return nil
}

View File

@ -13,7 +13,8 @@ import (
)
type FolderStatistics struct {
LastFile LastFile `json:"lastFile"`
LastFile LastFile `json:"lastFile"`
LastScan time.Time `json:"lastScan"`
}
type FolderStatisticsReference struct {
@ -59,8 +60,21 @@ func (s *FolderStatisticsReference) ReceivedFile(file string, deleted bool) {
s.ns.PutBool("lastFileDeleted", deleted)
}
func (s *FolderStatisticsReference) ScanCompleted() {
s.ns.PutTime("lastScan", time.Now())
}
func (s *FolderStatisticsReference) GetLastScanTime() time.Time {
lastScan, ok := s.ns.Time("lastScan")
if !ok {
return time.Time{}
}
return lastScan
}
func (s *FolderStatisticsReference) GetStatistics() FolderStatistics {
return FolderStatistics{
LastFile: s.GetLastFile(),
LastScan: s.GetLastScanTime(),
}
}