mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
fix: Subscribe only when needed
This commit is contained in:
parent
b955e933b2
commit
58eda7d555
10 changed files with 28 additions and 23 deletions
|
@ -11,8 +11,10 @@ const createBoard = (projectId, data, headers) =>
|
||||||
const createBoardWithImport = (projectId, data, requestId, headers) =>
|
const createBoardWithImport = (projectId, data, requestId, headers) =>
|
||||||
http.post(`/projects/${projectId}/boards?requestId=${requestId}`, data, headers);
|
http.post(`/projects/${projectId}/boards?requestId=${requestId}`, data, headers);
|
||||||
|
|
||||||
const getBoard = (id, headers) =>
|
const getBoard = (id, subscribe, headers) =>
|
||||||
socket.get(`/boards/${id}`, undefined, headers).then((body) => ({
|
socket
|
||||||
|
.get(`/boards/${id}${subscribe ? '?subscribe=true' : ''}`, undefined, headers)
|
||||||
|
.then((body) => ({
|
||||||
...body,
|
...body,
|
||||||
included: {
|
included: {
|
||||||
...body.included,
|
...body.included,
|
||||||
|
|
|
@ -9,7 +9,8 @@ const createUser = (data, headers) => socket.post('/users', data, headers);
|
||||||
|
|
||||||
const getUser = (id, headers) => socket.get(`/users/${id}`, undefined, headers);
|
const getUser = (id, headers) => socket.get(`/users/${id}`, undefined, headers);
|
||||||
|
|
||||||
const getCurrentUser = (headers) => socket.get('/users/me', undefined, headers);
|
const getCurrentUser = (subscribe, headers) =>
|
||||||
|
socket.get(`/users/me${subscribe ? '?subscribe=true' : ''}`, undefined, headers);
|
||||||
|
|
||||||
const updateUser = (id, data, headers) => socket.patch(`/users/${id}`, data, headers);
|
const updateUser = (id, data, headers) => socket.patch(`/users/${id}`, data, headers);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ export function* fetchBoardByCurrentPath() {
|
||||||
tasks,
|
tasks,
|
||||||
attachments,
|
attachments,
|
||||||
},
|
},
|
||||||
} = yield call(request, api.getBoard, boardId));
|
} = yield call(request, api.getBoard, boardId, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import api from '../../../api';
|
||||||
import mergeRecords from '../../../utils/merge-records';
|
import mergeRecords from '../../../utils/merge-records';
|
||||||
|
|
||||||
export function* fetchCore() {
|
export function* fetchCore() {
|
||||||
const { item: user } = yield call(request, api.getCurrentUser);
|
const { item: user } = yield call(request, api.getCurrentUser, true);
|
||||||
const { items: users1 } = yield call(request, api.getUsers);
|
const { items: users1 } = yield call(request, api.getUsers);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -62,7 +62,7 @@ export function* handleBoardMembershipCreate(boardMembership) {
|
||||||
if (isCurrentUser) {
|
if (isCurrentUser) {
|
||||||
let board2;
|
let board2;
|
||||||
try {
|
try {
|
||||||
({ item: board2 } = yield call(request, api.getBoard, boardMembership.boardId));
|
({ item: board2 } = yield call(request, api.getBoard, boardMembership.boardId, false));
|
||||||
} catch {
|
} catch {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ export function* fetchBoard(id) {
|
||||||
tasks,
|
tasks,
|
||||||
attachments,
|
attachments,
|
||||||
},
|
},
|
||||||
} = yield call(request, api.getBoard, id));
|
} = yield call(request, api.getBoard, id, true));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
yield put(actions.fetchBoard.failure(id, error));
|
yield put(actions.fetchBoard.failure(id, error));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -81,7 +81,7 @@ export function* handleLocationChange() {
|
||||||
tasks,
|
tasks,
|
||||||
attachments,
|
attachments,
|
||||||
},
|
},
|
||||||
} = yield call(request, api.getBoard, currentBoard.id));
|
} = yield call(request, api.getBoard, currentBoard.id, true));
|
||||||
} catch (error) {} // eslint-disable-line no-empty
|
} catch (error) {} // eslint-disable-line no-empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,6 @@ module.exports = {
|
||||||
request: this.req,
|
request: this.req,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.req.isSocket) {
|
|
||||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: board,
|
item: board,
|
||||||
included: {
|
included: {
|
||||||
|
|
|
@ -11,6 +11,9 @@ module.exports = {
|
||||||
regex: /^[0-9]+$/,
|
regex: /^[0-9]+$/,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
subscribe: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
exits: {
|
exits: {
|
||||||
|
@ -73,8 +76,8 @@ module.exports = {
|
||||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.req.isSocket) {
|
if (inputs.subscribe && this.req.isSocket) {
|
||||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
sails.sockets.join(this.req, `board:${board.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -13,6 +13,9 @@ module.exports = {
|
||||||
regex: /^[0-9]+|me$/,
|
regex: /^[0-9]+|me$/,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
subscribe: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
exits: {
|
exits: {
|
||||||
|
@ -26,8 +29,8 @@ module.exports = {
|
||||||
if (inputs.id === CURRENT_USER_ID) {
|
if (inputs.id === CURRENT_USER_ID) {
|
||||||
({ currentUser: user } = this.req);
|
({ currentUser: user } = this.req);
|
||||||
|
|
||||||
if (this.req.isSocket) {
|
if (inputs.subscribe && this.req.isSocket) {
|
||||||
sails.sockets.join(this.req, `user:${user.id}`); // TODO: only when subscription needed
|
sails.sockets.join(this.req, `user:${user.id}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user = await sails.helpers.users.getOne(inputs.id);
|
user = await sails.helpers.users.getOne(inputs.id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue