Skip to content

Conversation

@kpfleming
Copy link

When the bridge is restarted, Google Chat sends different
URLs for the avatar images for every participant in every room.
This happens even if the images have not changed, but sending
'avatar change' events into the Matrix rooms can be costly.

This patch computes a SHA256 hash of the image to see if the
image has actually changed; if not, the new URL is stored but no
Matrix event is sent.

This includes a database schema upgrade to v4.

@kpfleming
Copy link
Author

Examples of 'old' and 'new' photo URLs for one room participant:

https://lh3.googleusercontent.com/a-/AOh14GiPcv_V586eHWKP_MaIvUNP281g4BP8SAZLmeVwouV0EjBTIrl_srNEz82g7HVMA97m90y13kJtgUqjalhMrGRlNym1src_e1aV55d6PsPUxSTLQSD_2KRkC9Oj72jsqWdW1ADxI9x6FiVawZH1kw1Rh04ZI0IQqwSwt1vbuiHgFmc_y3G9hIx5KTh1U9nNY1JG-zndqQDzS_XrZFWFxAYA7RUQihOeNibXHLYTNGd2opeOzZFbbs_nqLbgLfgHMEyZxkZiPtW9sF8DizWDI-tUPmHIdQGgK5bdnFFdFpONT_VOQY3W8W11F2qr9Q3d-bo82DUe4MNuCWCMDFWmv3ZAZr4EILcf0tnohnJ-XewSiqgRct5KdRgo5cIh0yXwDXAkM0xpUFbTplUtwYHzRh6FIfbzyhTLBsmaogFwC3iCPkxa49akbThyU5kQLiEbq1LuukZBDEqzrUuPBJq7bxA-isercmK5jvfZEbrOre5Bdv45od5CA9appYqeNKoMZm3DlEiPKrs5Wt8YPbMR4eZpTNuWX-_-5Pu9FrVpQKVynulQ3VbXW7EhLCZYkQUDRnQI7rts_-60uAzSABy-wa_E770BOXm7D53e76TmgEXBNAH-ZDieokClN5E1uBjRY2MIhmmRj6YruJBaVtd1aTM51zppG99k-UklGk93kvPho9IaCVQSqkA-9rsZ6UOx0lQnBPQzxPuAJTOTIl4VU6iR0lXc1AwyFxtb_pCkix4myqW4Lecb0hGOfrdnSoe8cQ=k
https://lh3.googleusercontent.com/a-/AOh14GhayscTSYOLu6M0NbdlPtyGeQ2iO8wf7g91tBwNnz0BP4ooTCFd4KiMbVWIQOWydE8ZFPEEpQWUI7l1YoiC0Zoi6nGHSBNfAGnKS4r4TGKrTAl3qVwUDj9LO4FmTug6otAznRIN3JjvCNwoJ4NUfEUmJAn9wOcC1jsTDhMqB3H-gvHODm00-YkkxqsZfOTTZZ-ouIYOSyaNEUHBNKKq96TJokQgE4s-O4TqYwc55AxRcd2ZW_CI2s7hTaaFb65dk-AWrQPhV_LN3utYcnHbthmf6h1dxTWeQwZcJv1TvLsCmhM0I_KJg2XfgJ2EW_WeZvZ0ssoypY2ra3BAtzs4NFYMHp5ctVvC5Kbo_yquHelneGS62NWc9YvaegNQ_7vdqp4TM2sta_5kNsOAaExk9uBvHYdXYq8TXYd-7vNNrrezZwSWU5UIttg85HjVLco5JCgDiOYuikZMy9qpPyutOTJWgxVitaX46jTYERmVOwONRtF2l4y56O7LWqqFaU8gSRjJr4SSmBvZXguk_RyyaxY3artDzAvcIyFo-7pRYZ1CAEPPflTGQ7EBZNWLqY401jQD3YY27_kdETWzQKWwMqT-XoZWBConLi0nkJ9GAlK6NZFMTzs02zOFKbfO4haqVMU3m6qDVfXxhummLtRnYdb-QBw-OqizQyAncz8zR8l0JQ8wpCV8f9e1hcweG1_uEHRwKKDoQchHoPs7LbovrquTHTcoxdw2Z3pCew6Xmc_tEasTNQM8pEKr5D2KCw4zNw=k

They are so different that it would not be possible to know that they point to the same image.

@kpfleming
Copy link
Author

kpfleming commented Mar 18, 2022

FYI: We have this deployed in production now, with ~60 users in at least 700 bridged chats (and more than 15,000 'puppets' from the Google chat side), and it is working very well. We haven't seen any 'spurious' avatar-change events at all since it was deployed and the database was populated with hashes.

When the bridge is restarted, Google Chat sends different
URLs for the avatar images for every participant in every room.
This happens even if the images have not changed, but sending
'avatar change' events into the Matrix rooms can be costly.

This patch computes a SHA256 hash of the image to see if the
image has actually changed; if not, the new URL is stored but no
Matrix event is sent.

This includes a database schema upgrade to v4.
@tulir tulir merged commit b581e42 into mautrix:master Mar 29, 2022
@kpfleming kpfleming deleted the store-photo-hashes-to-avoid-avatar-updates branch March 29, 2022 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants