out-of-your-element/db/migrations/0002-optimise-profile-conte...

14 lines
577 B
JavaScript
Raw Normal View History

2023-09-29 04:41:11 +00:00
module.exports = async function(db) {
const hasher = await require("xxhash-wasm")()
const contents = db.prepare("SELECT distinct hashed_profile_content FROM sim_member").pluck().all()
const stmt = db.prepare("UPDATE sim_member SET hashed_profile_content = ? WHERE hashed_profile_content = ?")
db.transaction(() => {
for (const s of contents) {
if (!Buffer.isBuffer(s)) s = Buffer.from(s)
const unsignedHash = hasher.h64(eventID)
const signedHash = unsignedHash - 0x8000000000000000n // shifting down to signed 64-bit range
stmt.run(s, signedHash)
}
})()
}