-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Return attrs for more media repo APIs. #16611
Conversation
last_access_ts: int | ||
quarantined_by: Optional[str] | ||
safe_from_quarantine: bool | ||
|
||
|
||
@attr.s(slots=True, frozen=True, auto_attribs=True) | ||
class RemoteMedia: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#16545 covers the nullable columns for these.
@@ -54,11 +52,32 @@ class LocalMedia: | |||
media_length: int | |||
upload_name: str | |||
created_ts: int | |||
url_cache: Optional[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this and consolidated the (now) two spots we use it to return the same type, which I find easier to grok than having two separate, but really similar types.
" ORDER BY download_ts DESC LIMIT 1" | ||
) | ||
sql = """ | ||
SELECT response_code, expires_ts, og |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this was unused, so it was simpler to not return it.
@@ -267,23 +267,23 @@ def _assert_if_mxc_uris_purged( | |||
def _assert_mxc_uri_purge_state(mxc_uri: MXCUri, expect_purged: bool) -> None: | |||
"""Given an MXC URI, assert whether it has been purged or not.""" | |||
if mxc_uri.server_name == self.hs.config.server.server_name: | |||
found_media_dict = self.get_success( | |||
self.store.get_local_media(mxc_uri.media_id) | |||
found_media = bool( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting to a boolean was easier than trying to tell mypy that it was a union of two different types, especially when we just care if a result was returned for tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. (Casting would be my preference, anyway.)
class UrlCache: | ||
response_code: int | ||
expires_ts: int | ||
og: Union[str, bytes] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit icky---does it cause any pain for the consumers of this type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit icky---does it cause any pain for the consumers of this type?
The only consumer does an "if str, decode to bytes". I'm a bit skeptical of the comment there which says something about postgres vs. sqlite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matrix=> \d local_media_repository_url_cache
Table "matrix.local_media_repository_url_cache"
Column │ Type │ Collation │ Nullable │ Default
═══════════════╪═════════╪═══════════╪══════════╪═════════
url │ text │ │ │
response_code │ integer │ │ │
etag │ text │ │ │
expires_ts │ bigint │ │ │
og │ text │ │ │
media_id │ text │ │ │
download_ts │ bigint │ │ │
Indexes:
"local_media_repository_url_cache_by_url_download_ts" btree (url, download_ts)
"local_media_repository_url_cache_expires_idx" btree (expires_ts)
"local_media_repository_url_cache_media_idx" btree (media_id
And the schema dumps say
CREATE TABLE IF NOT EXISTS "local_media_repository_url_cache"( url TEXT, response_code INTEGER, etag TEXT, expires_ts BIGINT, og TEXT, media_id TEXT, download_ts BIGINT );
for sqlite.
Looks like it should always be a string to me, too. (Maybe this is some ancient py2 str
vs unicode
thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it should always be a string to me, too. (Maybe this is some ancient py2
str
vsunicode
thing?
This is my guess, but didn't want to break it. Maybe in a follow-up?
More on my war to kill of unneeded dicts.
A few spots in the media repo that we returned dictionaries are easy to convert to attr, so do that. 🎉 I don't think there's much surprising here.