started tuning the order saving and caching...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-15 03:28:18 +03:00
parent 9eaad5e6e8
commit f204503464
3 changed files with 27 additions and 12 deletions

View File

@ -899,7 +899,7 @@ module.Base = core.ImageGridFeatures.Feature({
'flipHorizontal',
'flipVertical',
],
function(_, target){ this.markChanged('images', [that.data.getImage(target)]) }],
function(_, target){ this.markChanged('images', [this.data.getImage(target)]) }],
],
})

View File

@ -858,6 +858,8 @@ var ChangesActions = actions.Actions({
Mark item(s) of section as changed...
.markChanged(<section>, [<item>, .. ])
NOTE: when marking section items, the new items will be added to
the set of already marked items.
NOTE: when .changes is null (i.e. everything changed, marked via
.markChanged('all')) then calling this with anything other
than 'none' will have no effect.
@ -894,7 +896,7 @@ var ChangesActions = actions.Actions({
// section items...
} else if(items instanceof Array) {
changes[section] = (changes[section] || []).concat(items)
changes[section] = (changes[section] || []).concat(items).unique()
this.changes = changes
// section(s)...

View File

@ -469,21 +469,34 @@ module.Sort = core.ImageGridFeatures.Feature({
['prepareIndexForWrite',
function(res){
var changed = this.changes == null
|| this.changes.sort_cache
var c = this.changes
if(changed && res.raw.sort_order){
res.index['sort_order'] = res.raw.sort_order
var save = function(attr){
if((c == null || c[attr]) && res.raw[attr]){
// full save...
if(c == null){
res.index[attr] = res.raw[attr]
// build diff...
} else {
var diff = {}
c[attr].forEach(function(k){ diff[k] = res.raw[attr][k] })
res.index[attr +'-diff'] = diff
}
if(changed && res.raw.sort_cache){
res.index['sort_cache'] = res.raw.sort_cache
}
}
save('sort_order')
save('sort_cache')
}],
// manage changes...
// XXX also need to mark 'sort_cache'
['sortImages',
function(_, target){ this.markChanged('data') }],
['saveOrder',
function(_, title){ this.markChanged('sort_order', [title]) }],
['cacheOrder',
function(){ this.markChanged('sort_cache', [this.data.sort_method]) }],
],
})