Return attrs for more media repo APIs.#16611
Conversation
|
|
||
|
|
||
| @attr.s(slots=True, frozen=True, auto_attribs=True) | ||
| class RemoteMedia: |
There was a problem hiding this comment.
#16545 covers the nullable columns for these.
| media_length: int | ||
| upload_name: str | ||
| created_ts: int | ||
| url_cache: Optional[str] |
There was a problem hiding this comment.
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.
Most of this was unused, so it was simpler to not return it.
| 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.
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.
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.
This feels a bit icky---does it cause any pain for the consumers of this type?
There was a problem hiding this comment.
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.
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.
Looks like it should always be a string to me, too. (Maybe this is some ancient py2
strvsunicodething?
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.