mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 21:47:10 -04:00
Move every Boards.find(idOrFirstObjectSelector, options) to the ReactiveCache (directory models/)
This commit is contained in:
parent
59ee616304
commit
f83ee124d0
5 changed files with 30 additions and 28 deletions
|
@ -1556,10 +1556,10 @@ Boards.uniqueTitle = title => {
|
|||
);
|
||||
const base = escapeForRegex(m.groups.title);
|
||||
const baseTitle = m.groups.title;
|
||||
boards = Boards.find({ title: new RegExp(`^${base}\\s*(\\[(?<num>\\d+)]\\s*$|\\s*$)`) });
|
||||
if (boards.count() > 0) {
|
||||
boards = ReactiveCache.getBoards({ title: new RegExp(`^${base}\\s*(\\[(?<num>\\d+)]\\s*$|\\s*$)`) });
|
||||
if (boards.length > 0) {
|
||||
let num = 0;
|
||||
Boards.find({ title: new RegExp(`^${base}\\s*\\[\\d+]\\s*$`) }).forEach(
|
||||
ReactiveCache.getBoards({ title: new RegExp(`^${base}\\s*\\[\\d+]\\s*$`) }).forEach(
|
||||
board => {
|
||||
const m = board.title.match(
|
||||
new RegExp('^(?<title>.*?)\\s*\\[(?<num>\\d+)]\\s*$'),
|
||||
|
@ -1589,7 +1589,8 @@ Boards.userSearch = (
|
|||
if (userId) {
|
||||
selector.$or.push({ members: { $elemMatch: { userId, isActive: true } } });
|
||||
}
|
||||
return Boards.find(selector, projection);
|
||||
const ret = ReactiveCache.getBoards(selector, projection);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Boards.userBoards = (
|
||||
|
@ -1617,7 +1618,7 @@ Boards.userBoards = (
|
|||
{ teams: { $elemMatch: { teamId: { $in: user.teamIds() }, isActive: true } } },
|
||||
];
|
||||
|
||||
return Boards.find(selector, projection);
|
||||
return ReactiveCache.getBoards(selector, projection);
|
||||
};
|
||||
|
||||
Boards.userBoardIds = (userId, archived = false, selector = {}) => {
|
||||
|
@ -1972,7 +1973,7 @@ if (Meteor.isServer) {
|
|||
req.userId === paramUserId,
|
||||
);
|
||||
|
||||
const data = Boards.find(
|
||||
const data = ReactiveCache.getBoards(
|
||||
{
|
||||
archived: false,
|
||||
'members.userId': paramUserId,
|
||||
|
@ -2008,7 +2009,7 @@ if (Meteor.isServer) {
|
|||
Authentication.checkUserId(req.userId);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: Boards.find(
|
||||
data: ReactiveCache.getBoards(
|
||||
{ permission: 'public' },
|
||||
{
|
||||
sort: { sort: 1 /* boards default sorting */ },
|
||||
|
@ -2040,8 +2041,8 @@ if (Meteor.isServer) {
|
|||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: {
|
||||
private: Boards.find({ permission: 'private' }).count(),
|
||||
public: Boards.find({ permission: 'public' }).count(),
|
||||
private: ReactiveCache.getBoards({ permission: 'private' }).length,
|
||||
public: ReactiveCache.getBoards({ permission: 'public' }).length,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
|
|
@ -170,25 +170,25 @@ CustomFields.allow({
|
|||
insert(userId, doc) {
|
||||
return allowIsAnyBoardMember(
|
||||
userId,
|
||||
Boards.find({
|
||||
ReactiveCache.getBoards({
|
||||
_id: { $in: doc.boardIds },
|
||||
}).fetch(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
update(userId, doc) {
|
||||
return allowIsAnyBoardMember(
|
||||
userId,
|
||||
Boards.find({
|
||||
ReactiveCache.getBoards({
|
||||
_id: { $in: doc.boardIds },
|
||||
}).fetch(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
remove(userId, doc) {
|
||||
return allowIsAnyBoardMember(
|
||||
userId,
|
||||
Boards.find({
|
||||
ReactiveCache.getBoards({
|
||||
_id: { $in: doc.boardIds },
|
||||
}).fetch(),
|
||||
}),
|
||||
);
|
||||
},
|
||||
fetch: ['userId', 'boardIds'],
|
||||
|
|
|
@ -33,7 +33,8 @@ const getBoardTitleWithMostActivities = (dateWithXdaysAgo, nbLimit) => {
|
|||
};
|
||||
|
||||
const getBoards = (boardIds) => {
|
||||
return Boards.find({ _id: { $in: boardIds } }).fetch();
|
||||
const ret = ReactiveCache.getBoards({ _id: { $in: boardIds } });
|
||||
return ret;
|
||||
};
|
||||
Meteor.startup(() => {
|
||||
WebApp.connectHandlers.use('/metrics', (req, res, next) => {
|
||||
|
@ -77,7 +78,7 @@ Meteor.startup(() => {
|
|||
metricsRes += '# Number of registered boards\n';
|
||||
|
||||
// Get number of registered boards
|
||||
resCount = Boards.find({ archived: false, type: 'board' }).count(); // KPI 3
|
||||
resCount = ReactiveCache.getBoards({ archived: false, type: 'board' }).length; // KPI 3
|
||||
metricsRes += 'wekan_registeredboards ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
||||
|
@ -86,7 +87,7 @@ Meteor.startup(() => {
|
|||
|
||||
// Get number of registered boards by registered users
|
||||
resCount =
|
||||
Boards.find({ archived: false, type: 'board' }).count() /
|
||||
ReactiveCache.getBoards({ archived: false, type: 'board' }).length /
|
||||
ReactiveCache.getUsers({}).length; // KPI 4
|
||||
metricsRes +=
|
||||
'wekan_registeredboardsBysRegisteredUsers ' + resCount + '\n';
|
||||
|
@ -96,11 +97,11 @@ Meteor.startup(() => {
|
|||
metricsRes += '# Number of registered boards\n';
|
||||
|
||||
// Get board numbers with only one member
|
||||
resCount = Boards.find({
|
||||
resCount = ReactiveCache.getBoards({
|
||||
archived: false,
|
||||
type: 'board',
|
||||
members: { $size: 1 },
|
||||
}).count(); // KPI 5
|
||||
}).length; // KPI 5
|
||||
metricsRes +=
|
||||
'wekan_registeredboardsWithOnlyOneMember ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
|
|
@ -2029,7 +2029,7 @@ if (Meteor.isServer) {
|
|||
delete data.services;
|
||||
|
||||
// get all boards where the user is member of
|
||||
let boards = Boards.find(
|
||||
let boards = ReactiveCache.getBoards(
|
||||
{
|
||||
type: 'board',
|
||||
'members.userId': req.userId,
|
||||
|
@ -2115,7 +2115,7 @@ if (Meteor.isServer) {
|
|||
}
|
||||
|
||||
// get all boards where the user is member of
|
||||
let boards = Boards.find(
|
||||
let boards = ReactiveCache.getBoards(
|
||||
{
|
||||
type: 'board',
|
||||
'members.userId': id,
|
||||
|
@ -2174,7 +2174,7 @@ if (Meteor.isServer) {
|
|||
});
|
||||
if (data !== undefined) {
|
||||
if (action === 'takeOwnership') {
|
||||
data = Boards.find(
|
||||
data = ReactiveCache.getBoards(
|
||||
{
|
||||
'members.userId': id,
|
||||
'members.isAdmin': true,
|
||||
|
@ -2268,7 +2268,7 @@ if (Meteor.isServer) {
|
|||
let data = ReactiveCache.getUser(userId);
|
||||
if (data !== undefined) {
|
||||
if (action === 'add') {
|
||||
data = Boards.find({
|
||||
data = ReactiveCache.getBoards({
|
||||
_id: boardId,
|
||||
}).map(function (board) {
|
||||
if (!board.hasMember(userId)) {
|
||||
|
@ -2329,7 +2329,7 @@ if (Meteor.isServer) {
|
|||
let data = ReactiveCache.getUser(userId);
|
||||
if (data !== undefined) {
|
||||
if (action === 'remove') {
|
||||
data = Boards.find({
|
||||
data = ReactiveCache.getBoards({
|
||||
_id: boardId,
|
||||
}).map(function (board) {
|
||||
if (board.hasMember(userId)) {
|
||||
|
|
|
@ -245,7 +245,7 @@ function buildSelector(queryParams) {
|
|||
const boards = Boards.userSearch(userId, {
|
||||
title: new RegExp(escapeForRegex(query), 'i'),
|
||||
});
|
||||
if (boards.count()) {
|
||||
if (boards.length) {
|
||||
boards.forEach(board => {
|
||||
queryBoards.push(board._id);
|
||||
});
|
||||
|
@ -372,7 +372,7 @@ function buildSelector(queryParams) {
|
|||
labels: { $elemMatch: { color: label.toLowerCase() } },
|
||||
});
|
||||
|
||||
if (boards.count()) {
|
||||
if (boards.length) {
|
||||
boards.forEach(board => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('board:', board);
|
||||
|
@ -396,7 +396,7 @@ function buildSelector(queryParams) {
|
|||
labels: { $elemMatch: { name: reLabel } },
|
||||
});
|
||||
|
||||
if (boards.count()) {
|
||||
if (boards.length) {
|
||||
boards.forEach(board => {
|
||||
board.labels
|
||||
.filter(boardLabel => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue