Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
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
Timo Ley
synapse
Commits
a4bb133b
Commit
a4bb133b
authored
7 years ago
by
Matthew Hodgson
Browse files
Options
Downloads
Patches
Plain Diff
fix thinkos galore
parent
cd3697e8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/handlers/user_directory.py
+6
-4
6 additions, 4 deletions
synapse/handlers/user_directory.py
synapse/storage/profile.py
+22
-9
22 additions, 9 deletions
synapse/storage/profile.py
synapse/storage/user_directory.py
+13
-7
13 additions, 7 deletions
synapse/storage/user_directory.py
with
41 additions
and
20 deletions
synapse/handlers/user_directory.py
+
6
−
4
View file @
a4bb133b
...
...
@@ -20,6 +20,7 @@ from synapse.api.constants import EventTypes, JoinRules, Membership
from
synapse.storage.roommember
import
ProfileInfo
from
synapse.util.metrics
import
Measure
from
synapse.util.async
import
sleep
from
synapse.types
import
get_localpart_from_id
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -53,6 +54,7 @@ class UserDirectoryHandler(object):
self
.
notifier
=
hs
.
get_notifier
()
self
.
is_mine_id
=
hs
.
is_mine_id
self
.
update_user_directory
=
hs
.
config
.
update_user_directory
self
.
include_pattern
=
hs
.
config
.
user_directory_include_pattern
# When start up for the first time we need to populate the user_directory.
# This is a set of user_id's we've inserted already
...
...
@@ -116,7 +118,7 @@ class UserDirectoryHandler(object):
irrespective of any rooms the user may be in.
"""
yield
self
.
store
.
update_profile_in_user_dir
(
user_id
,
profile
.
display_name
,
profile
.
avatar_url
,
user_id
,
profile
.
display_name
,
profile
.
avatar_url
,
None
,
)
@defer.inlineCallbacks
...
...
@@ -167,10 +169,10 @@ class UserDirectoryHandler(object):
logger
.
info
(
"
Processed all rooms.
"
)
if
self
.
hs
.
config
.
user_directory_include_pattern
:
logger
.
info
(
"
Doing initial update of user directory. %d users
"
,
len
(
user_ids
))
if
self
.
include_pattern
:
num_processed_users
=
0
user_ids
=
yield
self
.
store
.
get_all_local_users
()
logger
.
info
(
"
Doing initial update of user directory. %d users
"
,
len
(
user_ids
))
for
user_id
in
user_ids
:
# We add profiles for all users even if they don't match the
# include pattern, just in case we want to change it in future
...
...
@@ -415,7 +417,7 @@ class UserDirectoryHandler(object):
"""
logger
.
debug
(
"
Adding new local user to dir, %r
"
,
user_id
)
profile
=
yield
self
.
store
.
get_profileinfo
(
user_id
)
profile
=
yield
self
.
store
.
get_profileinfo
(
get_localpart_from_id
(
user_id
)
)
row
=
yield
self
.
store
.
get_user_in_directory
(
user_id
)
if
not
row
:
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/profile.py
+
22
−
9
View file @
a4bb133b
...
...
@@ -16,6 +16,7 @@
from
twisted.internet
import
defer
from
synapse.storage.roommember
import
ProfileInfo
from
synapse.api.errors
import
StoreError
from
._base
import
SQLBaseStore
...
...
@@ -28,16 +29,28 @@ class ProfileStore(SQLBaseStore):
desc
=
"
create_profile
"
,
)
@defer.inlineCallbacks
def
get_profileinfo
(
self
,
user_localpart
):
profile
=
self
.
_simple_select_one
(
table
=
"
profiles
"
,
keyvalues
=
{
"
user_id
"
:
user_localpart
},
retcols
=
(
"
displayname
"
,
"
avatar_url
"
),
desc
=
"
get_profileinfo
"
,
)
return
ProfileInfo
(
avatar_url
=
profile
.
avatar_url
,
displayname
=
profile
.
displayname
,
try
:
profile
=
yield
self
.
_simple_select_one
(
table
=
"
profiles
"
,
keyvalues
=
{
"
user_id
"
:
user_localpart
},
retcols
=
(
"
displayname
"
,
"
avatar_url
"
),
desc
=
"
get_profileinfo
"
,
)
except
StoreError
,
e
:
if
e
.
code
==
404
:
# no match
defer
.
returnValue
(
ProfileInfo
(
None
,
None
))
return
else
:
raise
defer
.
returnValue
(
ProfileInfo
(
avatar_url
=
profile
[
'
avatar_url
'
],
display_name
=
profile
[
'
displayname
'
],
)
)
def
get_profile_displayname
(
self
,
user_localpart
):
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/user_directory.py
+
13
−
7
View file @
a4bb133b
...
...
@@ -640,13 +640,17 @@ class UserDirectoryStore(SQLBaseStore):
}
"""
include_pattern_clause
=
""
include_pattern_join
=
""
include_pattern_where_clause
=
""
if
self
.
hs
.
config
.
user_directory_include_pattern
:
include_pattern_clause
=
"
OR d.user_id LIKE
'
%s
'"
%
(
self
.
hs
.
config
.
user_directory_include_pattern
)
include_pattern_join
=
"""
LEFT JOIN (
SELECT user_id FROM user_directory
WHERE user_id LIKE
'
%s
'
) AS ld USING (user_id)
"""
%
(
self
.
hs
.
config
.
user_directory_include_pattern
)
logger
.
error
(
"
include
pattern
is %s
"
%
(
include_pattern
))
include
_
pattern
_where_clause
=
"
OR ld.user_id IS NOT NULL
"
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
full_query
,
exact_query
,
prefix_query
=
_parse_query_postgres
(
search_term
)
...
...
@@ -665,6 +669,7 @@ class UserDirectoryStore(SQLBaseStore):
SELECT other_user_id AS user_id FROM users_who_share_rooms
WHERE user_id = ? AND share_private
) AS s USING (user_id)
%s
WHERE
(s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
AND vector @@ to_tsquery(
'
english
'
, ?)
...
...
@@ -690,7 +695,7 @@ class UserDirectoryStore(SQLBaseStore):
display_name IS NULL,
avatar_url IS NULL
LIMIT ?
"""
%
(
include_pattern_clause
)
"""
%
(
include_pattern_
join
,
include_pattern_where_
clause
)
args
=
(
user_id
,
full_query
,
exact_query
,
prefix_query
,
limit
+
1
,)
elif
isinstance
(
self
.
database_engine
,
Sqlite3Engine
):
search_query
=
_parse_query_sqlite
(
search_term
)
...
...
@@ -704,6 +709,7 @@ class UserDirectoryStore(SQLBaseStore):
SELECT other_user_id AS user_id FROM users_who_share_rooms
WHERE user_id = ? AND share_private
) AS s USING (user_id)
%s
WHERE
(s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
AND value MATCH ?
...
...
@@ -712,7 +718,7 @@ class UserDirectoryStore(SQLBaseStore):
display_name IS NULL,
avatar_url IS NULL
LIMIT ?
"""
%
(
include_pattern_clause
)
"""
%
(
include_pattern_
join
,
include_pattern_where_
clause
)
args
=
(
user_id
,
search_query
,
limit
+
1
)
else
:
# This should be unreachable.
...
...
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