Commit cae14556 authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Network: avoid peer's avatar image to wink

[fix] Network: avoid images to wink, on peer/block items (remove ':rebind:' prefix in avatar binding)
[enh] BMA: use a specific cache prefix
[enh] ES http, graph: always use a cache prefix, and clear cache when ES node changed
[enh] Refactor code that use cache (always use csCache.constants, distinguish of request by path cache, etc.)
[enh] Disable rebind in on <ng-template>, when not need (add a prefix '::' before template path)
parent b3339140
......@@ -38,18 +38,18 @@ fi
### Sign extension
case "$1" in
pre)
web-ext sign "--api-key=${AMO_JWT_ISSUER}" "--api-secret=${AMO_JWT_SECRET}" "--source-dir=${PROJECT_DIR}/dist/web/ext" "--artifacts-dir=${PROJECT_DIR}/dist/web/build" --id=${WEB_EXT_ID} --channel=unlisted
if [[ $? -ne 0 ]]; then
exit 1
fi
web-ext sign "--api-key=${AMO_JWT_ISSUER}" "--api-secret=${AMO_JWT_SECRET}" "--source-dir=${PROJECT_DIR}/dist/web/ext" "--artifacts-dir=${PROJECT_DIR}/dist/web/build" --id=${WEB_EXT_ID} --channel=unlisted
if [[ $? -ne 0 ]]; then
exit 1
fi
;;
rel)
web-ext sign "--api-key=${AMO_JWT_ISSUER}" "--api-secret=${AMO_JWT_SECRET}" "--source-dir=${PROJECT_DIR}/dist/web/ext" "--artifacts-dir=${PROJECT_DIR}/dist/web/build" --id=${WEB_EXT_ID} --channel=listed
if [[ $? -ne 0 ]]; then
web-ext sign "--api-key=${AMO_JWT_ISSUER}" "--api-secret=${AMO_JWT_SECRET}" "--source-dir=${PROJECT_DIR}/dist/web/ext" "--artifacts-dir=${PROJECT_DIR}/dist/web/build" --id=${WEB_EXT_ID} --channel=listed
# Comment out, because always failed with message:
# "Your add-on has been submitted for review. It passed validation but could not be automatically signed because this is a listed add-on."
#exit 1
fi
#if [[ $? -ne 0 ]]; then
# exit 1
#fi
;;
*)
echo "No task given"
......
This diff is collapsed.
......@@ -7,7 +7,8 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
var
sockets = [],
cachePrefix = 'csHttp-'
defaultCachePrefix = 'csHttp-',
allCachePrefixes = {};
;
if (!timeout) {
......@@ -94,7 +95,10 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
function getResourceWithCache(host, port, path, useSsl, maxAge, autoRefresh, forcedTimeout, cachePrefix) {
var url = getUrl(host, port, path, useSsl);
cachePrefix = cachePrefix || defaultCachePrefix;
maxAge = maxAge || csCache.constants.LONG;
allCachePrefixes[cachePrefix] = true;
//console.debug('[http] will cache ['+url+'] ' + maxAge + 'ms' + (autoRefresh ? ' with auto-refresh' : ''));
return function(params) {
......@@ -233,7 +237,7 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
_open(self, null, params);
}
else if (closeEvent) {
console.debug('[http] TODO -- Unexpected close of websocket [{0}]: error code: '.format(path), closeEvent);
console.debug('[http] Unexpected close of websocket [{0}]: error code: '.format(path), closeEvent && closeEvent.code || closeEvent);
// Force new connection
self.delegate = null;
......@@ -494,11 +498,18 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
return compareVersionNumbers(minVersion, actualVersion) <= 0;
}
var cache = angular.copy(csCache.constants);
cache.clear = function() {
console.debug('[http] Cleaning cache...');
function clearCache(cachePrefix) {
cachePrefix = cachePrefix || defaultCachePrefix;
console.debug("[http] Cleaning cache {prefix: '{0}'}...".format(cachePrefix));
csCache.clear(cachePrefix);
};
}
function clearAllCache() {
console.debug('[http] Cleaning all caches...');
_.keys(allCachePrefixes).forEach(function(cachePrefix) {
csCache.clear(cachePrefix);
});
}
return {
get: getResource,
......@@ -519,7 +530,10 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
compare: compareVersionNumbers,
isCompatible: isVersionCompatible
},
cache: cache
cache: angular.merge({
clear: clearCache,
clearAll: clearAllCache
}, csCache.constants)
};
})
;
......@@ -311,6 +311,11 @@ function ESWotIdentityViewController($scope, $ionicPopover, $q, $controller, $ti
});
};
/**
* Delete the user profile (need moderator access, on Cs+ pod)
* @param confirm
* @returns {*}
*/
$scope.delete = function(confirm) {
if (!confirm) {
......@@ -323,6 +328,12 @@ function ESWotIdentityViewController($scope, $ionicPopover, $q, $controller, $ti
});
}
// TODO: ask for deletion of all data ? (e.g. message, comment, likes, etc.)
// if (angular.isUndefined(allData)) {
// return UIUtils.alert.confirm(...)
// ...
// }
return UIUtils.loading.show()
.then(function() {
return esProfile.remove($scope.formData.pubkey);
......@@ -347,7 +358,7 @@ function ESWotIdentityViewController($scope, $ionicPopover, $q, $controller, $ti
// Load likes,
$scope.loadLikes(pubkey);
// Update moderator right
// Enable deletion, if moderator
$scope.canDelete = $scope.formData.profile && csWallet.isLogin() && csWallet.data.moderator === true;
}
......
angular.module('cesium.es.blockchain.services', ['cesium.services', 'cesium.es.http.services'])
.factory('esBlockchain', function($rootScope, $q, $timeout, BMA, esHttp) {
.factory('esBlockchain', function($rootScope, $q, $timeout, BMA, csCache, esHttp) {
'ngInject';
function EsBlockchain() {
......@@ -31,9 +31,9 @@ angular.module('cesium.es.blockchain.services', ['cesium.services', 'cesium.es.h
block: {},
raw: {
block: {
search: esHttp.post('/:currency/block/_search', esHttp.cache.SHORT),
search: esHttp.post('/:currency/block/_search', csCache.constants.SHORT),
searchText: esHttp.get('/:currency/block/_search?q=:text'),
get: esHttp.get('/:currency/block/:number/_source', esHttp.cache.SHORT)
get: esHttp.get('/:currency/block/:number/_source', csCache.constants.SHORT)
}
},
regexp: {
......
......@@ -14,7 +14,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
console.debug('[ES] [https] Enable SSL (forced by config or detected in URL)');
}
function EsHttp(host, port, useSsl, useCache) {
function EsHttp(host, port, useSsl, enableCache) {
var
that = this,
......@@ -42,15 +42,21 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
that.data = {
isFallback: false
};
that.cache = _emptyCache();
that.cache = {
enable: angular.isDefined(enableCache) ? enableCache : false, // need here because used in get() function
};
that.raw = {
getByPath: {},
postByPath: {},
wsByPath: {}
};
that.api = new Api(this, "esHttp");
that.started = false;
that.init = init;
init(host, port, useSsl, useCache);
that.useCache = angular.isDefined(useCache) ? useCache : false; // need here because used in get() function
init(host, port, useSsl);
function init(host, port, useSsl, useCache) {
function init(host, port, useSsl) {
// Use settings as default
if (!host && csSettings.data) {
host = host || (csSettings.data.plugins && csSettings.data.plugins.es ? csSettings.data.plugins.es.host : null);
......@@ -100,14 +106,6 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
return new RegExp(regexpContent);
}
function _emptyCache() {
return {
getByPath: {},
postByPath: {},
wsByPath: {}
};
}
function onSettingsReset(data, deferred) {
deferred = deferred || $q.defer();
......@@ -126,14 +124,18 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
return deferred.promise;
}
that.cleanCache = function() {
console.debug('[ES] [http] Cleaning requests cache...');
_.keys(that.cache.wsByPath).forEach(function(key) {
var sock = that.cache.wsByPath[key];
that.clearAllCache = function() {
console.debug("[ES] [http] Cleaning cache {prefix: '{0}'}...".format(cachePrefix));
_.keys(that.raw.wsByPath).forEach(function(key) {
var sock = that.raw.wsByPath[key];
sock.close();
});
that.cache = _emptyCache();
angular.merge(that.raw, {
getByPath: {},
postByPath: {},
wsByPath: {}
});
csCache.clear(cachePrefix);
};
......@@ -158,8 +160,8 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
that.get = function (path, cacheTime) {
cacheTime = that.useCache && cacheTime;
var cacheKey = path + (cacheTime ? ('#'+cacheTime) : '');
cacheTime = that.cache.enable && cacheTime;
var requestKey = path + (cacheTime ? ('#'+cacheTime) : '');
var getRequestFn = function(params) {
if (!that.started) {
......@@ -172,7 +174,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
});
}
var request = that.cache.getByPath[cacheKey];
var request = that.raw.getByPath[requestKey];
if (!request) {
if (cacheTime) {
request = csHttp.getWithCache(that.host, that.port, path, that.useSsl, cacheTime, null, null, cachePrefix);
......@@ -180,7 +182,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
else {
request = csHttp.get(that.host, that.port, path, that.useSsl);
}
that.cache.getByPath[cacheKey] = request;
that.raw.getByPath[requestKey] = request;
}
return request(params);
};
......@@ -200,10 +202,10 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
});
}
var request = that.cache.postByPath[path];
var request = that.raw.postByPath[path];
if (!request) {
request = csHttp.post(that.host, that.port, path, that.useSsl);
that.cache.postByPath[path] = request;
that.raw.postByPath[path] = request;
}
return request(obj, params);
};
......@@ -212,16 +214,16 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
that.ws = function(path) {
return function() {
var sock = that.cache.wsByPath[path];
var sock = that.raw.wsByPath[path];
if (!sock || sock.isClosed()) {
sock = csHttp.ws(that.host, that.port, path, that.useSsl);
// When close, remove from cache
sock.onclose = function() {
delete that.cache.wsByPath[path];
delete that.raw.wsByPath[path];
};
that.cache.wsByPath[path] = sock;
that.raw.wsByPath[path] = sock;
}
return sock;
};
......@@ -290,7 +292,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
.then(function (confirm) {
if (!confirm) return false; // stop the loop
that.cleanCache();
that.clearAllCache();
that.init(fallbackNode.host, fallbackNode.port, fallbackNode.useSsl || fallbackNode.port == 443);
......@@ -364,7 +366,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
setIsFallbackNode(false); // will be re-computed during start phase
delete that._startPromise;
if (that.alive) {
that.cleanCache();
that.clearAllCache();
that.alive = false;
that.started = false;
that.api.node.raise.stop();
......@@ -745,6 +747,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
that.api.registerEvent('node', 'start');
that.api.registerEvent('node', 'stop');
var exports = {
getServer: csHttp.getServer,
node: {
......@@ -788,7 +791,9 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
parseAsHtml: parseAsHtml,
findObjectInTree: findObjectInTree
},
cache: csHttp.cache,
cache: {
clearAll: that.clearAllCache
},
constants: constants
};
exports.constants.regexp = regexp;
......@@ -798,8 +803,8 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic
var service = new EsHttp(undefined, undefined, undefined, true);
service.instance = function(host, port, useSsl, useCache) {
return new EsHttp(host, port, useSsl, useCache);
service.instance = function(host, port, useSsl, enableCache) {
return new EsHttp(host, port, useSsl, enableCache);
};
service.lightInstance = function(host, port, useSsl, timeout) {
......
......@@ -10,7 +10,7 @@ angular.module('cesium.es.profile.services', ['cesium.services', 'cesium.es.http
})
.factory('esProfile', function($rootScope, $q, esHttp, SocialUtils, csWot, csWallet, csPlatform, esSettings, esLike) {
.factory('esProfile', function($rootScope, $q, esHttp, SocialUtils, csWot, csWallet, csCache, csPlatform, esSettings, esLike) {
'ngInject';
var
......@@ -19,10 +19,11 @@ angular.module('cesium.es.profile.services', ['cesium.services', 'cesium.es.http
that.raw = {
getFields: esHttp.get('/user/profile/:id?&_source_exclude=avatar._content&_source=:fields'),
get: esHttp.get('/user/profile/:id?&_source_exclude=avatar._content', esHttp.cache.MEDIUM),
getAll: esHttp.get('/user/profile/:id', esHttp.cache.MEDIUM),
search: esHttp.post('/user/profile/_search', esHttp.cache.MEDIUM),
mixedSearch: esHttp.post('/user,page,group/profile,record/_search', esHttp.cache.MEDIUM)
get: esHttp.get('/user/profile/:id?&_source_exclude=avatar._content', csCache.constants.MEDIUM),
getAll: esHttp.get('/user/profile/:id', csCache.constants.MEDIUM),
search: esHttp.post('/user/profile/_search', csCache.constants.MEDIUM),
mixedSearch: esHttp.post('/user,page,group/profile,record/_search', csCache.constants.MEDIUM),
remove: esHttp.record.remove("user","profile")
};
function getAvatarAndName(pubkey) {
......@@ -353,6 +354,15 @@ angular.module('cesium.es.profile.services', ['cesium.services', 'cesium.es.http
return deferred.promise;
}
function removeProfile(pubkey, options) {
return that.raw.remove(pubkey, options)
.then(function(res) {
csCache.clear('csWot-');
csCache.clear('csWot-');
return res;
});
}
function removeListeners() {
_.forEach(listeners, function(remove){
remove();
......@@ -392,7 +402,7 @@ angular.module('cesium.es.profile.services', ['cesium.services', 'cesium.es.http
get: getProfile,
add: esHttp.record.post('/user/profile', {tagFields: ['title', 'description'], ignoreFields: ['enableGeoPoint', 'descriptionHtml', 'moderator']}),
update: esHttp.record.post('/user/profile/:id/_update', {tagFields: ['title', 'description'], ignoreFields: ['enableGeoPoint', 'descriptionHtml', 'moderator']}),
remove: esHttp.record.remove("user","profile"),
remove: removeProfile,
avatar: esHttp.get('/user/profile/:id?_source=avatar'),
fillAvatars: fillAvatars,
like: esLike.instance('user', 'profile')
......
......@@ -10,81 +10,84 @@ angular.module('cesium.es.wot.services', ['ngResource', 'cesium.es.http.services
user: {
event: esHttp.post('/user/event/_search')
}
},
loadMemberships = function(pubkey, options) {
options = options || {};
};
var result = (options.cache !== false) ? membershipsCache.get(pubkey) : null;
if (result) return $q.when(result);
function loadMemberships(pubkey, options) {
options = options || {};
// Get user events on membership state
var request = {
"size": 1000,
"query": {
"bool": {
"filter": [
{"term": {"recipient" : pubkey }},
{"terms": {"code" : ["MEMBER_JOIN","MEMBER_ACTIVE","MEMBER_LEAVE","MEMBER_EXCLUDE","MEMBER_REVOKE"] }}
]
}
},
"sort" : [
{ "time" : {"order" : "asc"}}
],
_source: ["code", "time"]
};
var result = (options.cache !== false) ? membershipsCache.get(pubkey) : null;
if (result) return $q.when(result);
return raw.user.event(request)
// Get user events on membership state
var request = {
"size": 1000,
"query": {
"bool": {
"filter": [
{"term": {"recipient" : pubkey }},
{"terms": {"code" : ["MEMBER_JOIN","MEMBER_ACTIVE","MEMBER_LEAVE","MEMBER_EXCLUDE","MEMBER_REVOKE"] }}
]
}
},
"sort" : [
{ "time" : {"order" : "asc"}}
],
_source: ["code", "time"]
};
.then(function(res) {
if (!res.hits || !res.hits.total) return;
return raw.user.event(request)
// Compute member periods
var lastJoinTime;
var result = res.hits.hits.reduce(function(res, hit){
var isMember = hit._source.code == 'MEMBER_JOIN' || hit._source.code == 'MEMBER_ACTIVE';
// If join
if (isMember && !lastJoinTime) {
lastJoinTime = hit._source.time;
}
// If leave
else if (!isMember && lastJoinTime) {
// Add an entry
res = res.concat({
joinTime: lastJoinTime,
leaveTime: hit._source.time
});
lastJoinTime = 0; // reset
}
return res;
}, []);
.then(function(res) {
if (!res.hits || !res.hits.total) return;
if (lastJoinTime) {
// Add last entry if need
result.push({
// Compute member periods
var lastJoinTime;
var result = res.hits.hits.reduce(function(res, hit){
var isMember = hit._source.code === 'MEMBER_JOIN' || hit._source.code === 'MEMBER_ACTIVE';
// If join
if (isMember && !lastJoinTime) {
lastJoinTime = hit._source.time;
}
// If leave
else if (!isMember && lastJoinTime) {
// Add an entry
res = res.concat({
joinTime: lastJoinTime,
leaveTime: moment().utc().unix()
leaveTime: hit._source.time
});
lastJoinTime = 0; // reset
}
return res;
}, []);
// Put in the cache
membershipsCache.put(pubkey, result);
if (lastJoinTime) {
// Add last entry if need
result.push({
joinTime: lastJoinTime,
leaveTime: moment().utc().unix()
});
}
return result;
});
},
// Put in the cache
membershipsCache.put(pubkey, result);
cleanCache = function() {
console.debug('[ES] [wot] Clean cache...');
csCache.clear(cachePrefix);
};
return result;
});
};
function cleanAllCache() {
console.debug("[ES] [wot] Cleaning cache {prefix: '{0}'}...".format(cachePrefix));
csCache.clear(cachePrefix);
}
// Listen if node changed
esHttp.api.node.on.stop($rootScope, cleanCache, this);
esHttp.api.node.on.stop($rootScope, cleanAllCache, this);
return {
memberships: loadMemberships
memberships: loadMemberships,
cache: {
clearAll: cleanAllCache
}
};
});
......@@ -46,6 +46,6 @@
<!-- blocks (small screens) -->
<ng-if ng-if=":rebind:smallscreen">
<ng-repeat ng-repeat="block in :rebind:search.results track by block.number"
ng-include="'templates/blockchain/item_block.html'">
ng-include="::'templates/blockchain/item_block.html'">
</ng-repeat>
</ng-if>
......@@ -21,6 +21,6 @@
</ion-nav-buttons>
<ion-content class="padding no-padding-xs no-padding-sm" scroll="true">
<ng-include src="'plugins/es/templates/blockchain/lookup_form.html'"></ng-include>
<ng-include src="::'plugins/es/templates/blockchain/lookup_form.html'"></ng-include>
</ion-content>
</ion-view>
......@@ -92,7 +92,7 @@
<ion-list class="list list-blocks" ng-class="::motion.ionListClass">
<ng-include src="'plugins/es/templates/blockchain/items_blocks.html'"></ng-include>
<ng-include src="::'plugins/es/templates/blockchain/items_blocks.html'"></ng-include>
</ion-list>
......
......@@ -35,7 +35,7 @@
</div>
</div>
<ng-include src="'plugins/es/templates/common/item_comment_content.html'"></ng-include>
<ng-include src="::'plugins/es/templates/common/item_comment_content.html'"></ng-include>
<div class="card-footer gray">
<small class="underline">
......
......@@ -14,7 +14,7 @@
<div class="padding-right">
<ng-repeat ng-repeat="comment in comments.result track by comment.id"
ng-include="'plugins/es/templates/common/item_comment.html'">
ng-include="::'plugins/es/templates/common/item_comment.html'">
</ng-repeat>
</div>
......
<ion-list class="list" ng-class="::motion.ionListClass">
<ng-include src="'plugins/es/templates/document/items_documents.html'"></ng-include>
<ng-include src="::'plugins/es/templates/document/items_documents.html'"></ng-include>
</ion-list>
......
......@@ -12,6 +12,6 @@
<ion-content class="padding no-padding-xs no-padding-sm" scroll="true">
<ng-include src="'plugins/es/templates/document/lookup_form.html'"></ng-include>
<ng-include src="::'plugins/es/templates/document/lookup_form.html'"></ng-include>
</ion-content>
</ion-view>
......@@ -88,7 +88,7 @@
<ion-list class="list" ng-class="::motion.ionListClass">
<ng-include src="'plugins/es/templates/document/items_documents.html'"></ng-include>
<ng-include src="::'plugins/es/templates/document/items_documents.html'"></ng-include>
</ion-list>
......
......@@ -49,7 +49,7 @@
</div>
<!-- pictures -->
<ng-include src="'plugins/es/templates/common/edit_pictures.html'"></ng-include>
<ng-include src="::'plugins/es/templates/common/edit_pictures.html'"></ng-include>
<div class="item item-divider" translate>GROUP.GENERAL_DIVIDER</div>
......@@ -85,7 +85,7 @@
</div>
<!-- social networks -->
<ng-include src="'plugins/es/templates/common/edit_socials.html'" ng-controller="ESSocialsEditCtrl"></ng-include>
<ng-include src="::'plugins/es/templates/common/edit_socials.html'" ng-controller="ESSocialsEditCtrl"></ng-include>
</div>
......
......@@ -25,5 +25,5 @@
</div>
<ng-repeat ng-repeat="group in :rebind:search.results"
ng-include="'plugins/es/templates/group/item_group.html'">
ng-include="::'plugins/es/templates/group/item_group.html'">
</ng-repeat>
......@@ -11,6 +11,6 @@
</ion-nav-buttons>
<ion-content class="padding no-padding-xs no-padding-sm" scroll="true">
<ng-include src="'plugins/es/templates/group/lookup_form.html'"></ng-include>
<ng-include src="::'plugins/es/templates/group/lookup_form.html'"></ng-include>
</ion-content>
</ion-view>
......@@ -73,7 +73,7 @@
<div class="list {{::motion.ionListClass}}" ng-if="!$scope.search.loading">
<ng-include src="'plugins/es/templates/group/items_groups.html'"></ng-include>
<ng-include src="::'plugins/es/templates/group/items_groups.html'"></ng-include>
</div>
......
......@@ -126,7 +126,7 @@
<div class="lazy-load">
<!-- pictures -->
<ng-include src="'plugins/es/templates/common/view_pictures.html'"></ng-include>
<ng-include src="::'plugins/es/templates/common/view_pictures.html'"></ng-include>
<span class="item item-divider" ng-if="formData.pubkey">
......@@ -143,7 +143,7 @@
</div>
<!-- comments -->
<ng-include src="'plugins/es/templates/common/view_comments.html'"></ng-include>
<ng-include src="::'plugins/es/templates/common/view_comments.html'"></ng-include>
</div>
</div>
......