Skip to content

Commit 88bee54

Browse files
authored
Merge pull request #154 from nteske/master
Adding Comparison Between Cache And New Data
2 parents 9dddf28 + f19767f commit 88bee54

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

widget/controllers/widget.feed.controller.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,46 @@
6262
});
6363
};
6464

65+
var checkForNewDataFromYouTube = function (cache){
66+
var compareDataFromCacheAndYouTube = function(result){
67+
var isUnchanged=false;
68+
if(cache.items && result.items && result.items.length){
69+
if(cache.items.length == result.items.length){
70+
var flag=false;
71+
for (let i = 0; i < cache.items.length; i++) {
72+
if(cache.items[i].id!=result.items[i].id){
73+
flag=true;
74+
}
75+
}
76+
if(!flag){
77+
isUnchanged=true;
78+
}
79+
}
80+
}
81+
if(!isUnchanged){
82+
WidgetFeed.videos = [];
83+
WidgetFeed.busy = false;
84+
WidgetFeed.nextPageToken = null;
85+
setTimeout(() => {
86+
if(!$scope.loading){
87+
getFeedVideosSuccess(result);
88+
}
89+
}, 0);
90+
if (!$scope.$$phase) $scope.$digest();
91+
}
92+
};
93+
var errorWithComperation = function(err){
94+
console.error("Error while getting data", err);
95+
};
96+
97+
if (currentPlayListId && currentPlayListId !== "1") {
98+
YoutubeApi.getFeedVideos(
99+
currentPlayListId,
100+
VIDEO_COUNT.LIMIT,
101+
null
102+
).then(compareDataFromCacheAndYouTube, errorWithComperation);
103+
}
104+
};
65105
/*
66106
* Fetch user's data from datastore
67107
*/
@@ -72,6 +112,7 @@
72112
if (err || !data || data.rssUrl != result.data.content.rssUrl || !data.forcedCleanupv2)
73113
return;
74114
getFeedVideosSuccess(data);
115+
checkForNewDataFromYouTube(data);
75116
});
76117

77118
WidgetFeed.data = result.data;

youtube.zip

-427 KB
Binary file not shown.

0 commit comments

Comments
 (0)