Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
0c5100d2
Unverified
Commit
0c5100d2
authored
4 years ago
by
Diego Sampaio
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] Room's list showing all rooms with same name (#20176)
parent
0cfb988a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/startup/migrations/index.js
+1
-0
1 addition, 0 deletions
server/startup/migrations/index.js
server/startup/migrations/v213.js
+89
-0
89 additions, 0 deletions
server/startup/migrations/v213.js
with
90 additions
and
0 deletions
server/startup/migrations/index.js
+
1
−
0
View file @
0c5100d2
...
...
@@ -209,4 +209,5 @@ import './v209';
import
'
./v210
'
;
import
'
./v211
'
;
import
'
./v212
'
;
import
'
./v213
'
;
import
'
./xrun
'
;
This diff is collapsed.
Click to expand it.
server/startup/migrations/v213.js
0 → 100644
+
89
−
0
View file @
0c5100d2
import
{
Migrations
}
from
'
../../../app/migrations
'
;
import
{
Subscriptions
,
Rooms
}
from
'
../../../app/models/server/raw
'
;
const
updateSubscriptions
=
async
()
=>
{
const
cursor
=
Subscriptions
.
find
({
t
:
'
d
'
},
{
projection
:
{
rid
:
1
,
u
:
1
}
});
let
actions
=
[];
for
await
(
const
sub
of
cursor
)
{
const
room
=
await
Rooms
.
findOne
({
_id
:
sub
.
rid
},
{
projection
:
{
usernames
:
1
}
});
if
(
!
room
)
{
console
.
log
(
`[migration] room record not found:
${
sub
.
rid
}
`
);
continue
;
}
if
(
!
room
.
usernames
||
room
.
usernames
.
length
===
0
)
{
console
.
log
(
`[migration] room without usernames:
${
sub
.
rid
}
`
);
continue
;
}
const
name
=
room
.
usernames
.
filter
((
u
)
=>
u
!==
sub
.
u
.
username
)
.
sort
()
.
join
(
'
,
'
)
||
sub
.
u
.
username
;
if
(
!
name
)
{
console
.
log
(
`[migration] subscription without name
${
sub
.
_id
}
`
);
continue
;
}
actions
.
push
({
updateMany
:
{
filter
:
{
_id
:
sub
.
_id
},
update
:
{
$set
:
{
name
,
_updatedAt
:
new
Date
()
}
},
},
});
if
(
actions
.
length
===
1000
)
{
await
Subscriptions
.
col
.
bulkWrite
(
actions
,
{
ordered
:
false
});
actions
=
[];
}
}
if
(
actions
.
length
)
{
await
Subscriptions
.
col
.
bulkWrite
(
actions
,
{
ordered
:
false
});
}
};
Migrations
.
add
({
version
:
213
,
up
()
{
Promise
.
await
((
async
()
=>
{
const
options
=
{
projection
:
{
rid
:
1
,
u
:
1
,
name
:
1
},
};
const
cursor
=
Subscriptions
.
find
({
t
:
'
d
'
},
options
).
sort
({
_updatedAt
:
1
}).
limit
(
100
);
const
total
=
await
cursor
.
count
();
// if number of subscription is low, we can go ahead and fix them all
if
(
total
<
1000
)
{
return
updateSubscriptions
();
}
// otherwise we'll first see if they're broken
const
subs
=
await
cursor
.
toArray
();
const
subsTotal
=
subs
.
length
;
const
subsWithRoom
=
await
Promise
.
all
(
subs
.
map
(
async
(
sub
)
=>
({
sub
,
room
:
await
Rooms
.
findOne
({
_id
:
sub
.
rid
},
{
projection
:
{
usernames
:
1
}
}),
})));
const
wrongSubs
=
subsWithRoom
.
filter
(({
room
})
=>
room
&&
room
.
usernames
&&
room
.
usernames
.
length
>
0
)
.
filter
(({
room
,
sub
})
=>
{
const
name
=
room
.
usernames
.
filter
((
u
)
=>
u
!==
sub
.
u
.
username
)
.
sort
()
.
join
(
'
,
'
)
||
sub
.
u
.
username
;
return
name
!==
sub
.
name
;
}).
length
;
// if less then 5% of subscriptions are wrong, we're fine, doesn't need to do anything
if
(
wrongSubs
/
subsTotal
<
0.05
)
{
return
;
}
return
updateSubscriptions
();
})());
},
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment