properly clear the query cache

This commit is contained in:
Bernhard Posselt 2013-04-11 20:32:34 +02:00
Родитель a9fb379b37
Коммит ce6b20c59e
8 изменённых файлов: 62 добавлений и 18 удалений

Просмотреть файл

@ -114,16 +114,19 @@ button.action:hover {
}
.failed {
background-color: #EB9DA6 !important;
background-color: #F2FF63 !important;
text-shadow: none !important;
font-weight: bold;
}
.failed a:hover,
.failed:hover a {
background-color: #F2FF63 !important;
}
.failed .message {
font-weight: normal;
padding: 5px 20px 5px 32px;
text-transform: none;
background-color: #E83A4E;
text-shadow: none;
color: #fefefe;
}
.folder .feed.failed .message {

Просмотреть файл

@ -128,6 +128,7 @@ NewLoading, _ExistsError) ->
create: (url, parentId=0, onSuccess=null, onFailure=null) ->
onSuccess or= ->
onFailure or= ->
parentId = parseInt(parentId, 10)
if angular.isUndefined(url) or url.trim() == ''
throw new Error()

Просмотреть файл

@ -59,7 +59,7 @@ angular.module('News').factory '_FeedModel',
angular.isUndefined(item.id)
if updateById or updateByUrlHash
@update(data)
@update(data, clearCache)
else
# if the item is not yet in the name cache it must be added
@_urlHash[data.urlHash] = data
@ -71,6 +71,8 @@ angular.module('News').factory '_FeedModel',
# if there is no id we just want it to appear in the list
else
@_data.push(data)
if clearCache
@_invalidateCache()
update: (data, clearCache=true) ->
@ -129,7 +131,7 @@ angular.module('News').factory '_FeedModel',
getFolderUnreadCount: (folderId) ->
query = new _EqualQuery('folderId', folderId)
query = new _EqualQuery('folderId', parseInt(folderId))
count = 0
for feed in @get(query)
count += feed.unreadCount
@ -138,7 +140,7 @@ angular.module('News').factory '_FeedModel',
getAllOfFolder: (folderId) ->
query = new _EqualQuery('folderId', folderId)
query = new _EqualQuery('folderId', parseInt(folderId))
return @get(query)

Просмотреть файл

@ -50,7 +50,7 @@ angular.module('News').factory '_FolderModel',
angular.isUndefined(item.id)
if updateById or updateByName
@update(data)
@update(data, clearCache)
else
# if the item is not yet in the name cache it must be added
@_nameCache[data.name] = data
@ -62,6 +62,8 @@ angular.module('News').factory '_FolderModel',
# if there is no id we just want it to appear in the list
else
@_data.push(data)
if clearCache
@_invalidateCache()
update: (data, clearCache=true) ->

Просмотреть файл

@ -745,6 +745,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
}
onSuccess || (onSuccess = function() {});
onFailure || (onFailure = function() {});
parentId = parseInt(parentId, 10);
if (angular.isUndefined(url) || url.trim() === '') {
throw new Error();
}
@ -1361,13 +1362,16 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
updateById = angular.isDefined(data.id) && angular.isDefined(this.getById(data.id));
updateByUrlHash = angular.isDefined(item) && angular.isUndefined(item.id);
if (updateById || updateByUrlHash) {
return this.update(data);
return this.update(data, clearCache);
} else {
this._urlHash[data.urlHash] = data;
if (angular.isDefined(data.id)) {
return FeedModel.__super__.add.call(this, data, clearCache);
} else {
return this._data.push(data);
this._data.push(data);
if (clearCache) {
return this._invalidateCache();
}
}
}
};
@ -1434,7 +1438,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
FeedModel.prototype.getFolderUnreadCount = function(folderId) {
var count, feed, query, _i, _len, _ref;
query = new _EqualQuery('folderId', folderId);
query = new _EqualQuery('folderId', parseInt(folderId));
count = 0;
_ref = this.get(query);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -1447,7 +1451,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
FeedModel.prototype.getAllOfFolder = function(folderId) {
var query;
query = new _EqualQuery('folderId', folderId);
query = new _EqualQuery('folderId', parseInt(folderId));
return this.get(query);
};
@ -1516,13 +1520,16 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
updateById = angular.isDefined(data.id) && angular.isDefined(this.getById(data.id));
updateByName = angular.isDefined(item) && angular.isUndefined(item.id);
if (updateById || updateByName) {
return this.update(data);
return this.update(data, clearCache);
} else {
this._nameCache[data.name] = data;
if (angular.isDefined(data.id)) {
return FolderModel.__super__.add.call(this, data, clearCache);
} else {
return this._data.push(data);
this._data.push(data);
if (clearCache) {
return this._invalidateCache();
}
}
}
};

Просмотреть файл

@ -309,4 +309,6 @@ describe 'FeedBl', ->
expect(onFailure).toHaveBeenCalled()
expect(@FeedModel.getByUrlHash(hex_md5('johns')).error).toBe(
@response.msg)
@response.msg)

Просмотреть файл

@ -105,4 +105,15 @@ describe 'FeedModel', ->
expect(@FeedModel.size()).toBe(1)
it 'should clear invalidate the query cache on adding folder with name', =>
item = {faviconLink: null, urlHash: 'hi', test: 'heheh', folderId: 0}
expect(@FeedModel.getAllOfFolder(0).length).toBe(0)
@FeedModel.add(item, false)
expect(@FeedModel.getAllOfFolder(0).length).toBe(0)
item2 = {faviconLink: null, urlHash: 'his', test: 'heheh', folderId: 0}
@FeedModel.add(item2)
expect(@FeedModel.getAllOfFolder(0).length).toBe(2)

Просмотреть файл

@ -25,7 +25,7 @@ describe 'FolderModel', ->
beforeEach module 'News'
beforeEach inject (@FolderModel, @_Model) =>
beforeEach inject (@FolderModel, @_Model, @_EqualQuery) =>
it 'should extend model', =>
@ -93,4 +93,20 @@ describe 'FolderModel', ->
expect(@FolderModel.getByName('Hobo').id).toBe(3)
expect(@FolderModel.getByName('Hobo').test).toBe('hoho')
expect(@FolderModel.getById(3).test).toBe('hoho')
expect(@FolderModel.size()).toBe(1)
expect(@FolderModel.size()).toBe(1)
it 'should clear invalidate the query cache on adding folder with name', =>
item = {name: 'name1', test: 'hi'}
query = new @_EqualQuery('test', 'hi')
expect(@FolderModel.get(query).length).toBe(0)
@FolderModel.add(item, false)
expect(@FolderModel.get(query).length).toBe(0)
item2 = {name: 'name', test: 'hi'}
@FolderModel.add(item2)
expect(@FolderModel.get(query).length).toBe(2)