refactor(stores): read affected rows off WriteResult

Every database client returns affectedRows and anyRowsAffected, so the
`affectedRows ?? changes ?? 0` fallbacks in ShareStore, NotificationStore,
UserStore and UserBlockStore read those directly.
This commit is contained in:
Daniel Salazar committed 2026-10-10 19:53:48 -04:00
1 parent 9baa804048
commit 96f0cef342
4 files changed
+14 -27

No files matched your search

@@ -202,7 +202,7 @@ export class NotificationStore extends PuterStore {
'UPDATE `notification` SET `value` = ?, `shown` = NULL WHERE `uid` = ? AND `user_id` = ? AND `acknowledged` IS NULL',
[serialized, uid, userId],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
async markAcknowledged(uid, userId) {
@@ -211,7 +211,7 @@ export class NotificationStore extends PuterStore {
'UPDATE `notification` SET `acknowledged` = ? WHERE `uid` = ? AND `user_id` = ? AND `acknowledged` IS NULL',
[now, uid, userId],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
async markShown(uid, userId) {
@@ -220,7 +220,7 @@ export class NotificationStore extends PuterStore {
'UPDATE `notification` SET `shown` = ? WHERE `uid` = ? AND `user_id` = ? AND `shown` IS NULL',
[now, uid, userId],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
/**
@@ -240,7 +240,7 @@ export class NotificationStore extends PuterStore {
`WHERE \`user_id\` = ? AND \`shown\` IS NULL AND \`uid\` IN (${placeholders})`,
[now, userId, ...unique],
);
return result?.affectedRows ?? result?.changes ?? 0;
return result.affectedRows;
}
async deleteByUid(uid, userId) {
@@ -248,7 +248,7 @@ export class NotificationStore extends PuterStore {
'DELETE FROM `notification` WHERE `uid` = ? AND `user_id` = ?',
[uid, userId],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
/**
@@ -283,7 +283,7 @@ export class NotificationStore extends PuterStore {
});
const result = await this.clients.db.write(statement, [batch]);
return result?.affectedRows ?? result?.changes ?? 0;
return result.affectedRows;
}
// -- Internals ----------------------------------------------------
+5 -5
View File
@@ -814,7 +814,7 @@ export class ShareStore extends PuterStore {
? [holderUserId, fsentryId, issuerUserId]
: [holderUserId, fsentryId],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
/**
@@ -861,7 +861,7 @@ export class ShareStore extends PuterStore {
`DELETE FROM \`share\` WHERE \`fsentry_id\` IN (${placeholders})`,
fsentryIds,
);
return result?.affectedRows ?? result?.changes ?? 0;
return result.affectedRows;
}
/**
@@ -925,7 +925,7 @@ export class ShareStore extends PuterStore {
`DELETE FROM \`share\` WHERE \`uid\` IN (${placeholders})`,
retired.map((row) => row.uid),
);
return result?.affectedRows ?? result?.changes ?? 0;
return result.affectedRows;
}
async deleteByUid(uid) {
@@ -933,7 +933,7 @@ export class ShareStore extends PuterStore {
'DELETE FROM `share` WHERE `uid` = ?',
[uid],
);
return (result?.affectedRows ?? result?.changes ?? 0) > 0;
return result.anyRowsAffected;
}
// -- Anyone with the link -----------------------------------------
@@ -1083,7 +1083,7 @@ export class ShareStore extends PuterStore {
'DELETE FROM `share` WHERE `fsentry_id` = ? AND `anyone` = 1',
[fsentryId],
);
const removed = (result?.affectedRows ?? result?.changes ?? 0) > 0;
const removed = result.anyRowsAffected;
if (removed) await this.#markLinkRevoked();
return removed;
}
+2 -10
View File
@@ -711,16 +711,8 @@ export class UserStore extends PuterStore {
[...values, userId],
);
if (guard) {
const affected =
(result as { affectedRows?: number; changes?: number })
?.affectedRows ??
(result as { affectedRows?: number; changes?: number })
?.changes ??
0;
// Nothing was written, so there are no cache keys to retire.
if (affected === 0) return false;
}
// Nothing was written, so there are no cache keys to retire.
if (guard && !result.anyRowsAffected) return false;
const fresh = await this.getByProperty('id', userId, { force: true });
@@ -90,11 +90,6 @@ export class UserBlockStore extends PuterStore {
'DELETE FROM `user_block` WHERE `blocker_user_id` = ? AND `blocked_user_id` = ?',
[blockerUserId, blockedUserId],
);
return (
((result as { affectedRows?: number; changes?: number })
?.affectedRows ??
(result as { changes?: number })?.changes ??
0) > 0
);
return result.anyRowsAffected;
}
}