Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
🥺
conduwuit
Commits
7ba9263c
Unverified
Commit
7ba9263c
authored
4 years ago
by
Timo
Browse files
Options
Downloads
Patches
Plain Diff
improvement: show most recent PDUs first when searching
parent
36655463
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/client_server/account.rs
+4
-1
4 additions, 1 deletion
src/client_server/account.rs
src/database/rooms.rs
+11
-2
11 additions, 2 deletions
src/database/rooms.rs
src/utils.rs
+10
-6
10 additions, 6 deletions
src/utils.rs
with
25 additions
and
9 deletions
src/client_server/account.rs
+
4
−
1
View file @
7ba9263c
...
...
@@ -145,7 +145,10 @@ pub fn register_route(
}
if
missing_username
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
MissingParam
,
"Missing username field."
));
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
MissingParam
,
"Missing username field."
,
));
}
let
password
=
if
is_guest
{
...
...
This diff is collapsed.
Click to expand it.
src/database/rooms.rs
+
11
−
2
View file @
7ba9263c
...
...
@@ -965,6 +965,7 @@ pub fn search_pdus<'a>(
self
.tokenids
.scan_prefix
(
&
prefix2
)
.keys
()
.rev
()
// Newest pdus first
.filter_map
(|
r
|
r
.ok
())
.map
(|
key
|
{
let
pduid_index
=
key
...
...
@@ -983,7 +984,14 @@ pub fn search_pdus<'a>(
.filter_map
(|
r
|
r
.ok
())
});
Ok
((
utils
::
common_elements
(
iterators
)
.unwrap
(),
words
))
Ok
((
utils
::
common_elements
(
iterators
,
|
a
,
b
|
{
// We compare b with a because we reversed the iterator earlier
b
.cmp
(
a
)
})
.unwrap
(),
words
,
))
}
pub
fn
get_shared_rooms
<
'a
>
(
...
...
@@ -1015,7 +1023,8 @@ pub fn get_shared_rooms<'a>(
.filter_map
(|
r
|
r
.ok
())
});
utils
::
common_elements
(
iterators
)
// We use the default compare function because keys are sorted correctly (not reversed)
utils
::
common_elements
(
iterators
,
Ord
::
cmp
)
.expect
(
"users is not empty"
)
.map
(|
bytes
|
{
RoomId
::
try_from
(
utils
::
string_from_bytes
(
&*
bytes
)
.map_err
(|
_
|
{
...
...
This diff is collapsed.
Click to expand it.
src/utils.rs
+
10
−
6
View file @
7ba9263c
use
argon2
::{
Config
,
Variant
};
use
cmp
::
Ordering
;
use
rand
::
prelude
::
*
;
use
sled
::
IVec
;
use
std
::{
cmp
,
convert
::
TryInto
,
time
::{
SystemTime
,
UNIX_EPOCH
},
};
...
...
@@ -63,6 +65,7 @@ pub fn calculate_hash(password: &str) -> Result<String, argon2::Error> {
pub
fn
common_elements
(
mut
iterators
:
impl
Iterator
<
Item
=
impl
Iterator
<
Item
=
IVec
>>
,
check_order
:
impl
Fn
(
&
IVec
,
&
IVec
)
->
Ordering
,
)
->
Option
<
impl
Iterator
<
Item
=
IVec
>>
{
let
first_iterator
=
iterators
.next
()
?
;
let
mut
other_iterators
=
iterators
.map
(|
i
|
i
.peekable
())
.collect
::
<
Vec
<
_
>>
();
...
...
@@ -72,12 +75,13 @@ pub fn common_elements(
.iter_mut
()
.map
(|
it
|
{
while
let
Some
(
element
)
=
it
.peek
()
{
if
element
>
target
{
return
false
;
}
else
if
element
==
target
{
return
true
;
}
else
{
it
.next
();
match
check_order
(
element
,
target
)
{
Ordering
::
Greater
=>
return
false
,
// We went too far
Ordering
::
Equal
=>
return
true
,
// Element is in both iters
Ordering
::
Less
=>
{
// Keep searching
it
.next
();
}
}
}
...
...
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