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