##// END OF EJS Templates
goto-switcher: optimized performance and query capabilities....
goto-switcher: optimized performance and query capabilities. - Previous implementation had on significant bug. The use of LIMIT 20 was limiting results BEFORE auth checks. In case of large ammount of similarly named repositories user didn't had access too, the result goto search was empty. This was becuase first 20 items fetched didn't pass permission checks and final auth list was empty. To fix this we now use proper filtering for auth using SQL. It means we first check user allowed repositories, and add this as a filter so end result from database is already to only the accessible repositories.

File last commit:

r1970:ef3d81a8 default
r2038:2bdf9d4d default
Show More
rhodecode-app.js
150 lines | 6.0 KiB | application/javascript | JavascriptLexer
frontend: introduce rhodecode-app for more complex cross element wiring
r787 ccLog = Logger.get('RhodeCodeApp');
ccLog.setLevel(Logger.OFF);
var rhodeCodeApp = Polymer({
is: 'rhodecode-app',
notifications: move all notifications into polymer for consistency fix #4201
r822 attached: function () {
frontend: introduce rhodecode-app for more complex cross element wiring
r787 ccLog.debug('rhodeCodeApp created');
$.Topic('/notifications').subscribe(this.handleNotifications.bind(this));
favicon: added favicon notifications
r882 $.Topic('/favicon/update').subscribe(this.faviconUpdate.bind(this));
frontend: ensure polyfills are loaded as early as possible
r880 $.Topic('/connection_controller/subscribe').subscribe(
this.subscribeToChannelTopic.bind(this));
// this event can be used to coordinate plugins to do their
// initialization before channelstream is kicked off
$.Topic('/__MAIN_APP__').publish({});
frontend: introduce rhodecode-app for more complex cross element wiring
r787
notifications: move all notifications into polymer for consistency fix #4201
r822 for (var i = 0; i < alertMessagePayloads.length; i++) {
$.Topic('/notifications').publish(alertMessagePayloads[i]);
}
topics: remove dependency on __REGISTER__ so we avoid race condition
r838 this.kickoffChannelstreamPlugin();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 },
/** proxy to channelstream connection */
getChannelStreamConnection: function () {
return this.$['channelstream-connection'];
},
handleNotifications: function (data) {
notifications: different approach with fixed/standard container
r1483 var elem = document.getElementById('notifications');
if(elem){
elem.handleNotification(data);
}
frontend: introduce rhodecode-app for more complex cross element wiring
r787 },
favicon: added favicon notifications
r882 faviconUpdate: function (data) {
this.$$('rhodecode-favicon').counter = data.count;
},
frontend: introduce rhodecode-app for more complex cross element wiring
r787 /** opens connection to ws server */
kickoffChannelstreamPlugin: function (data) {
ccLog.debug('kickoffChannelstreamPlugin');
var channels = ['broadcast'];
var addChannels = this.checkViewChannels();
for (var i = 0; i < addChannels.length; i++) {
channels.push(addChannels[i]);
}
channelstream: connect only when enabled
r798 if (window.CHANNELSTREAM_SETTINGS && CHANNELSTREAM_SETTINGS.enabled){
frontend: ensure polyfills are loaded as early as possible
r880 var channelstreamConnection = this.getChannelStreamConnection();
channelstream: connect only when enabled
r798 channelstreamConnection.connectUrl = CHANNELSTREAM_URLS.connect;
channelstreamConnection.subscribeUrl = CHANNELSTREAM_URLS.subscribe;
channelstreamConnection.websocketUrl = CHANNELSTREAM_URLS.ws + '/ws';
channelstreamConnection.longPollUrl = CHANNELSTREAM_URLS.longpoll + '/listen';
// some channels might already be registered by topic
for (var i = 0; i < channels.length; i++) {
channelstreamConnection.push('channels', channels[i]);
}
// append any additional channels registered in other plugins
$.Topic('/connection_controller/subscribe').processPrepared();
channelstreamConnection.connect();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 }
},
checkViewChannels: function () {
channelstream: push events with comments on single commits....
r1970 // subscribe to different channels data is sent.
var channels = [];
frontend: introduce rhodecode-app for more complex cross element wiring
r787 // subscribe to PR repo channel for PR's'
if (templateContext.pull_request_data.pull_request_id) {
var channelName = '/repo$' + templateContext.repo_name + '$/pr/' +
String(templateContext.pull_request_data.pull_request_id);
channels.push(channelName);
}
channelstream: push events with comments on single commits....
r1970
if (templateContext.commit_data.commit_id) {
var channelName = '/repo$' + templateContext.repo_name + '$/commit/' +
String(templateContext.commit_data.commit_id);
channels.push(channelName);
}
frontend: introduce rhodecode-app for more complex cross element wiring
r787 return channels;
},
/** subscribes users from channels in channelstream */
subscribeToChannelTopic: function (channels) {
components: small order of elements change and a cleanup
r983 var channelstreamConnection = this.getChannelStreamConnection();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 var toSubscribe = channelstreamConnection.calculateSubscribe(channels);
ccLog.debug('subscribeToChannelTopic', toSubscribe);
if (toSubscribe.length > 0) {
// if we are connected then subscribe
if (channelstreamConnection.connected) {
channelstreamConnection.subscribe(toSubscribe);
}
// not connected? just push channels onto the stack
else {
for (var i = 0; i < toSubscribe.length; i++) {
channelstreamConnection.push('channels', toSubscribe[i]);
}
}
}
},
/** publish received messages into correct topic */
receivedMessage: function (event) {
for (var i = 0; i < event.detail.length; i++) {
var message = event.detail[i];
if (message.message.topic) {
ccLog.debug('publishing', message.message.topic);
$.Topic(message.message.topic).publish(message);
}
else if (message.type === 'presence'){
$.Topic('/connection_controller/presence').publish(message);
}
else {
ccLog.warn('unhandled message', message);
}
}
},
handleConnected: function (event) {
components: small order of elements change and a cleanup
r983 var channelstreamConnection = this.getChannelStreamConnection();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 channelstreamConnection.set('channelsState',
event.detail.channels_info);
channelstreamConnection.set('userState', event.detail.state);
channelstreamConnection.set('channels', event.detail.channels);
this.propagageChannelsState();
},
handleSubscribed: function (event) {
components: small order of elements change and a cleanup
r983 var channelstreamConnection = this.getChannelStreamConnection();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 var channelInfo = event.detail.channels_info;
var channelKeys = Object.keys(event.detail.channels_info);
for (var i = 0; i < channelKeys.length; i++) {
var key = channelKeys[i];
channelstreamConnection.set(['channelsState', key], channelInfo[key]);
}
channelstreamConnection.set('channels', event.detail.channels);
this.propagageChannelsState();
},
/** propagates channel states on topics */
propagageChannelsState: function (event) {
components: small order of elements change and a cleanup
r983 var channelstreamConnection = this.getChannelStreamConnection();
frontend: introduce rhodecode-app for more complex cross element wiring
r787 var channel_data = channelstreamConnection.channelsState;
var channels = channelstreamConnection.channels;
for (var i = 0; i < channels.length; i++) {
var key = channels[i];
$.Topic('/connection_controller/channel_update').publish(
{channel: key, state: channel_data[key]}
);
}
}
});