Fix and test broken room bridge check #104

Merged
cadence merged 2 commits from l1s5/out-of-your-element:fix-room-bridged-sql-query into main 2026-11-04 22:26:37 +00:00
4 changed files with 13 additions and 26 deletions
Showing only changes of commit 75ead0edad - Show all commits

fixup! Fix and test broken room bridge check

l1s5 2026-11-03 22:08:26 +09:00
Signed by untrusted user: l1s5
GPG key ID: D0A90CC905B58D9B

View file

@ -0,0 +1,9 @@
BEGIN TRANSACTION;
DELETE FROM member_cache
WHERE room_id NOT IN (SELECT room_id FROM channel_room)
AND room_id NOT IN (SELECT space_id FROM guild_space)
AND room_id NOT IN (SELECT room_id FROM historical_channel_room)
AND room_id NOT IN (SELECT room_id FROM invite);
COMMIT;

View file

@ -422,7 +422,8 @@ async event => {
if (utils.eventSenderIsFromDiscord(event.state_key)) return if (utils.eventSenderIsFromDiscord(event.state_key)) return
if (!utils.isBridgedRoom(event.room_id)) return // don't cache members in unbridged rooms const exists = select("channel_room", "room_id", {room_id: event.room_id}).pluck().get() ?? select("guild_space", "space_id", {space_id: event.room_id}).pluck().get()
if (!exists) return // don't cache members in unbridged rooms
// Member is here // Member is here
let {powers: {[event.state_key]: memberPower}, tombstone} = await utils.getEffectivePower(event.room_id, [event.state_key], api) let {powers: {[event.state_key]: memberPower}, tombstone} = await utils.getEffectivePower(event.room_id, [event.state_key], api)

View file

@ -4,7 +4,7 @@ const assert = require("assert").strict
const Ty = require("../types") const Ty = require("../types")
const {tag} = require("@cloudrac3r/html-template-tag") const {tag} = require("@cloudrac3r/html-template-tag")
const passthrough = require("../passthrough") const passthrough = require("../passthrough")
const {db, select} = passthrough const {db} = passthrough
const {reg} = require("./read-registration") const {reg} = require("./read-registration")
const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex)) const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex))
@ -41,16 +41,6 @@ function eventSenderIsFromDiscord(sender) {
return false return false
} }
/**
* @param {string} roomID
* @returns {boolean} whether the room is a bridged channel or space
*/
function isBridgedRoom(roomID) {
if (select("channel_room", "room_id", {room_id: roomID}).get()) return true
if (select("guild_space", "space_id", {space_id: roomID}).get()) return true
return false
}
/** /**
* Event IDs are really big and have more entropy than we need. * Event IDs are really big and have more entropy than we need.
* If we want to store the event ID in the database, we can store a more compact version by hashing it with this. * If we want to store the event ID in the database, we can store a more compact version by hashing it with this.
@ -398,7 +388,6 @@ async function setUserPowerCascade(spaceID, mxid, power, api) {
module.exports.bot = bot module.exports.bot = bot
module.exports.BLOCK_ELEMENTS = BLOCK_ELEMENTS module.exports.BLOCK_ELEMENTS = BLOCK_ELEMENTS
module.exports.eventSenderIsFromDiscord = eventSenderIsFromDiscord module.exports.eventSenderIsFromDiscord = eventSenderIsFromDiscord
module.exports.isBridgedRoom = isBridgedRoom
module.exports.makeMxcPublic = makeMxcPublic module.exports.makeMxcPublic = makeMxcPublic
module.exports.getPublicUrlForMxc = getPublicUrlForMxc module.exports.getPublicUrlForMxc = getPublicUrlForMxc
module.exports.getEventIDHash = getEventIDHash module.exports.getEventIDHash = getEventIDHash

View file

@ -2,7 +2,7 @@
const {select} = require("../passthrough") const {select} = require("../passthrough")
const {test} = require("supertape") const {test} = require("supertape")
const {eventSenderIsFromDiscord, isBridgedRoom, getEventIDHash, MatrixStringBuilder, getViaServers, roomHasAtLeastVersion, removeCreatorsFromPowerLevels, setUserPower} = require("./utils") const {eventSenderIsFromDiscord, getEventIDHash, MatrixStringBuilder, getViaServers, roomHasAtLeastVersion, removeCreatorsFromPowerLevels, setUserPower} = require("./utils")
const util = require("util") const util = require("util")
/** @param {string[]} mxids */ /** @param {string[]} mxids */
@ -30,18 +30,6 @@ test("sender type: ooye puppet", t => {
t.ok(eventSenderIsFromDiscord("@_ooye_sheep:cadence.moe")) t.ok(eventSenderIsFromDiscord("@_ooye_sheep:cadence.moe"))
}) })
test("is bridged room: channel room", t => {
t.equal(isBridgedRoom("!kLRqKKUQXcibIMtOpl:cadence.moe"), true)
})
test("is bridged room: space", t => {
t.equal(isBridgedRoom("!jjmvBegULiLucuWEHU:cadence.moe"), true)
})
test("is bridged room: unbridged room", t => {
t.equal(isBridgedRoom("!unbridged:cadence.moe"), false)
})
test("event hash: hash is the same each time", t => { test("event hash: hash is the same each time", t => {
const eventID = "$example" const eventID = "$example"
t.equal(getEventIDHash(eventID), getEventIDHash(eventID)) t.equal(getEventIDHash(eventID), getEventIDHash(eventID))