wiz0u / WTelegramClient

Telegram Client API (MTProto) library written 100% in C# and .NET
https://wiz0u.github.io/WTelegramClient/
MIT License
996 stars 164 forks source link

Feature: check username in cache in AnalyzeInviteLink ? #148

Closed m0nax3 closed 1 year ago

m0nax3 commented 1 year ago

Something like this (I made for own app)

`
var username = url[start..end];

        ChatBase? existsInCache;
        lock (ChatsAndChannels)
        {
            existsInCache = ChatsAndChannels.Values.FirstOrDefault(f => f.MainUsername == username);
        }

        ChatBase chat;
        if (existsInCache == null)
        {
            lock (Users)
            {
               //yep, can be slow for 500k users, BUT still FASTER then FLOOD_WAIT_X10000 (^_^)
                if (Users.Values.Any(f => f.MainUsername == username))
                    return null;
            }

            var resolved = await Contacts_ResolveUsername(username);
            chat = resolved.Chat;
        }
        else
        {
            chat = existsInCache;
        }

`

wiz0u commented 1 year ago

I will consider part of your suggestion. However you should just cache the result of AnalyzeInviteLink for a given url, in order to avoid resolving always the same usernames