-
Notifications
You must be signed in to change notification settings - Fork 15
Shard 2536 rebase #277
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
base: dev
Are you sure you want to change the base?
Shard 2536 rebase #277
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
const sql = `SELECT * FROM receipts ORDER BY cycle DESC, timestamp DESC LIMIT ${count ? count : 100}` | ||
const receipts = (await db.all(receiptDatabase, sql)) as DbReceipt[] | ||
if (receipts.length > 0) { | ||
receipts.forEach((receipt: DbReceipt) => { | ||
deserializeDbReceipt(receipt) | ||
}) | ||
} | ||
if (config.VERBOSE) { | ||
Logger.mainLogger.debug('Receipt latest', receipts) | ||
const deserializedReceipts = await Promise.all(receipts.map((receipt: DbReceipt) => deserializeDbReceipt(receipt))) | ||
return deserializedReceipts | ||
} | ||
return receipts | ||
} catch (e) { |
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.
Suggestion: Returning the raw receipts
array when no results are found may cause type inconsistencies, as it is typed as DbReceipt[]
but the function promises Receipt[]
. Return an empty array instead to maintain type safety. [possible issue, importance: 7]
New proposed code:
export async function queryLatestReceipts(count: number): Promise<Receipt[]> {
if (!Number.isInteger(count)) {
Logger.mainLogger.error('queryLatestReceipts - Invalid count value')
return null
}
try {
const sql = `SELECT * FROM receipts ORDER BY cycle DESC, timestamp DESC LIMIT ${count ? count : 100}`
const receipts = (await db.all(receiptDatabase, sql)) as DbReceipt[]
if (receipts.length > 0) {
const deserializedReceipts = await Promise.all(receipts.map((receipt: DbReceipt) => deserializeDbReceipt(receipt)))
return deserializedReceipts
}
- return receipts
+ return []
} catch (e) {
Logger.mainLogger.error(e)
The promisified database helpers were incorrectly implemented. promisify expects the callback as the last argument, but the wrappers had the callback in the wrong position. This could cause unexpected behavior or runtime errors. Replaced incorrect promisify usage with explicit Promise wrappers that properly handle sqlite3's callback pattern. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
5ca8a8c
to
c1c162f
Compare
PR Type
Enhancement, Tests
Description
Introduced receipt signature compression/decompression for storage optimization
Added new
nodes
table for mapping public keys to node IDsImplemented in-memory LRU cache for node mappings
Added comprehensive tests for receipt signature transformer logic
Changes walkthrough 📝
Config.ts
Add receipt signature optimization config options
src/Config.ts
receiptSignatureOptimization
config option with sub-options.index.ts
Add nodes table for signature optimization
src/dbstore/index.ts
nodes
table in receipt database for signatureoptimization.
public_key
innodes
table.receipts.ts
Integrate signature compression/decompression in receipt storage
src/dbstore/receipts.ts
receiptTransformer.ts
Implement receipt signature compression and node mapping
src/middleware/receiptTransformer.ts
server.ts
Preload node cache on server startup
src/server.ts
receiptTransformer.test.ts
Add tests for receipt signature transformer logic
src/middleware/tests/receiptTransformer.test.ts