Skip to content

Custom Entity Database

Pre-release
Pre-release
Compare
Choose a tag to compare
@Lonami Lonami released this 05 Oct 12:05

The main feature of this release is that Telethon now has a custom database for all the entities you encounter, instead depending on @lru_cache on the .get_entity() method.

The EntityDatabase will, by default, cache all the users, chats and channels you find in memory for as long as the program is running. The session will, by default, save all key-value pairs of the entity identifiers and their hashes (since Telegram may send an ID that it thinks you already know about, we need to save this information).

You can prevent the EntityDatabase from saving users by setting client.session.entities.enabled = False, and prevent the Session from saving input entities at all by setting client.session.save_entities = False. You can also clear the cache for a certain user through client.session.entities.clear_cache(entity=None), which will clear all if no entity is given.

More things:

  • .sign_in accepts phones as integers.
  • .get_dialogs() doesn't fail on Windows anymore, and returns the right amount of dialogs.
  • New method to .delete_messages().
  • New ChannelPrivateError class
  • Changing the IP to which you connect to is as simple as client.session.server_address = 'ip', since now the server address is always queried from the session.
  • GeneralProxyError should be passed to the main thread again, so that you can handle it.