-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config limits for portal rooms #469
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work for preventing portal creation, but the errors are probably not displayed in any sensible way currently.
This works for portals, but we'd also like to limit for puppeted users. Looking at that now... |
7f8e7cf
to
6754c3f
Compare
Co-authored-by: Christian Paul <[email protected]>
Co-authored-by: Christian Paul <[email protected]>
Co-authored-by: Christian Paul <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DBPortal.count()
for some reason does not exceed 1.
mautrix_telegram/db/portal.py
Outdated
rows = cls.db.execute(select([func.count()])) | ||
try: | ||
count, = next(rows) | ||
return count | ||
except StopIteration: | ||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Baby's first Python commits (don't commit blindly):
rows = cls.db.execute(select([func.count()])) | |
try: | |
count, = next(rows) | |
return count | |
except StopIteration: | |
return 0 | |
return cls.db.query(func.count('*')).scalar() |
Please test this. I haven't actually run this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No good unfortunately,
AttributeError: 'Engine' object has no attribute 'query'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table to count rows in probably needs to be specified somewhere 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh derp, I thought that was implied somewhere
mautrix_telegram/db/portal.py
Outdated
@@ -64,3 +69,7 @@ def get_by_username(cls, username: str) -> Optional['Portal']: | |||
@classmethod | |||
def all(cls) -> Iterable['Portal']: | |||
yield from cls._select_all() | |||
|
|||
@classmethod | |||
def get_by_mxid(cls, mxid: RoomID) -> Integer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to have been changed accidentally
@@ -53,6 +53,11 @@ def get_by_tgid(cls, tgid: TelegramID, tg_receiver: TelegramID) -> Optional['Por | |||
def find_private_chats(cls, tg_receiver: TelegramID) -> Iterable['Portal']: | |||
yield from cls._select_all(cls.c.tg_receiver == tg_receiver, cls.c.peer_type == "user") | |||
|
|||
@classmethod | |||
def count(cls) -> int: | |||
count = cls.db.execute(select([func.count('*')]).select_from(Table("portal", MetaData()))).scalar() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might work
count = cls.db.execute(select([func.count('*')]).select_from(Table("portal", MetaData()))).scalar() | |
count = cls.db.execute(cls.t.select([func.count('*')])).scalar() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests showed that the room limit is enforced now. 👍
This needs to count the number of rooms where mxid is not null |
Trying to solve #466
I'm not sure if this works, but would value a review to see how close I am.