|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -from typing import Optional |
| 14 | +from typing import TYPE_CHECKING, Optional |
15 | 15 |
|
16 | 16 | from synapse.api.errors import StoreError |
17 | 17 | from synapse.storage._base import SQLBaseStore |
| 18 | +from synapse.storage.database import DatabasePool, LoggingDatabaseConnection |
18 | 19 | from synapse.storage.databases.main.roommember import ProfileInfo |
| 20 | +from synapse.types import UserID |
| 21 | + |
| 22 | +if TYPE_CHECKING: |
| 23 | + from synapse.server import HomeServer |
19 | 24 |
|
20 | 25 |
|
21 | 26 | class ProfileWorkerStore(SQLBaseStore): |
| 27 | + def __init__( |
| 28 | + self, |
| 29 | + database: DatabasePool, |
| 30 | + db_conn: LoggingDatabaseConnection, |
| 31 | + hs: "HomeServer", |
| 32 | + ): |
| 33 | + super().__init__(database, db_conn, hs) |
| 34 | + self.db_pool.updates.register_background_index_update( |
| 35 | + "profiles_full_user_id_key_idx", |
| 36 | + index_name="profiles_full_user_id_key", |
| 37 | + table="profiles", |
| 38 | + columns=["full_user_id"], |
| 39 | + unique=True, |
| 40 | + ) |
| 41 | + |
22 | 42 | async def get_profileinfo(self, user_localpart: str) -> ProfileInfo: |
23 | 43 | try: |
24 | 44 | profile = await self.db_pool.simple_select_one( |
@@ -54,28 +74,36 @@ async def get_profile_avatar_url(self, user_localpart: str) -> Optional[str]: |
54 | 74 | desc="get_profile_avatar_url", |
55 | 75 | ) |
56 | 76 |
|
57 | | - async def create_profile(self, user_localpart: str) -> None: |
| 77 | + async def create_profile(self, user_id: UserID) -> None: |
| 78 | + user_localpart = user_id.localpart |
58 | 79 | await self.db_pool.simple_insert( |
59 | | - table="profiles", values={"user_id": user_localpart}, desc="create_profile" |
| 80 | + table="profiles", |
| 81 | + values={"user_id": user_localpart, "full_user_id": user_id.to_string()}, |
| 82 | + desc="create_profile", |
60 | 83 | ) |
61 | 84 |
|
62 | 85 | async def set_profile_displayname( |
63 | | - self, user_localpart: str, new_displayname: Optional[str] |
| 86 | + self, user_id: UserID, new_displayname: Optional[str] |
64 | 87 | ) -> None: |
| 88 | + user_localpart = user_id.localpart |
65 | 89 | await self.db_pool.simple_upsert( |
66 | 90 | table="profiles", |
67 | 91 | keyvalues={"user_id": user_localpart}, |
68 | | - values={"displayname": new_displayname}, |
| 92 | + values={ |
| 93 | + "displayname": new_displayname, |
| 94 | + "full_user_id": user_id.to_string(), |
| 95 | + }, |
69 | 96 | desc="set_profile_displayname", |
70 | 97 | ) |
71 | 98 |
|
72 | 99 | async def set_profile_avatar_url( |
73 | | - self, user_localpart: str, new_avatar_url: Optional[str] |
| 100 | + self, user_id: UserID, new_avatar_url: Optional[str] |
74 | 101 | ) -> None: |
| 102 | + user_localpart = user_id.localpart |
75 | 103 | await self.db_pool.simple_upsert( |
76 | 104 | table="profiles", |
77 | 105 | keyvalues={"user_id": user_localpart}, |
78 | | - values={"avatar_url": new_avatar_url}, |
| 106 | + values={"avatar_url": new_avatar_url, "full_user_id": user_id.to_string()}, |
79 | 107 | desc="set_profile_avatar_url", |
80 | 108 | ) |
81 | 109 |
|
|
0 commit comments