Properly implement InputPhoto/InputDocument caching

Since uploading a file is done on the TelegramClient, and the
InputFiles are only valid for a short period of time, it only
makes sense to cache the sent media instead (which should not
expire). The problem is the MD5 is only needed when uploading
the file.

The solution is to allow this method to check for the wanted
cache, and if available, return an instance of that, so to
preserve the flexibility of both options (always InputFile,
or the cached InputPhoto/InputDocument) instead reuploading.
This commit is contained in:
Lonami Exo
2018-01-18 19:36:47 +01:00
parent 7e707dbbd9
commit 0e4611a593
2 changed files with 85 additions and 63 deletions

View File

@@ -457,7 +457,7 @@ class Session:
with self._db_lock:
self._conn.execute(
'insert into sent_files values (?,?,?,?,?)', (
'insert or replace into sent_files values (?,?,?,?,?)', (
md5_digest, file_size,
_SentFileType.from_type(type(instance)).value,
instance.id, instance.access_hash