'get chat ids from the cache (DB). remove found entries from `usernames`, `fullnames` & `groups`
:type session: sqlalchemy.orm.Session
:type usernames: list[str]
:type fullnames: list[tuple[str, str]]
:type groups: list[str]
:rtype: list[ChatIdEntry]'

@staticmethod
def _get_cached_chat_ids(session, usernames, fullnames, groups):

    chat_ids = list()
    cached_usernames = dict(((x.username, x) for x in session.query(ChatIdEntry).filter((ChatIdEntry.username != None)).all()))
    cached_fullnames = dict((((x.firstname, x.surname), x) for x in session.query(ChatIdEntry).filter((ChatIdEntry.firstname != None)).all()))
    cached_groups = dict(((x.group, x) for x in session.query(ChatIdEntry).filter((ChatIdEntry.group != None)).all()))
    len_ = len(usernames)
    for (i, username) in enumerate(reversed(usernames)):
        item = cached_usernames.get(username)
        if item:
            chat_ids.append(item)
            usernames.pop(((len_ - i) - 1))
    len_ = len(fullnames)
    for (i, fullname) in enumerate(reversed(fullnames)):
        item = cached_fullnames.get(fullname)
        if item:
            chat_ids.append(item)
            fullnames.pop(((len_ - i) - 1))
    len_ = len(groups)
    for (i, grp) in enumerate(reversed(groups)):
        item = cached_groups.get(grp)
        if item:
            chat_ids.append(item)
            groups.pop(((len_ - i) - 1))
    return chat_ids
