Skip to content

Commit

Permalink
feat(sqlite bundles): record all parent/child relationships for match…
Browse files Browse the repository at this point in the history
…ing data items PE-3769

We don't want a data item with the same ID to appear multiple times in
GraphQL, so we only insert unique IDs into new_data_items. However, we'd
still like to have a record of all the bundles containing a particular
ID. This is important if a bundle is removed (due to content moderation)
or the parent association needs to be changed for any other unforeseen
reason.
  • Loading branch information
djwhitt committed Jul 18, 2023
1 parent 613aaae commit f8eab58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/database/sql/bundles/import.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-- insertBundleDataItem
INSERT INTO bundle_data_items (
id, parent_id, root_transaction_id, indexed_at
) VALUES (
@id, @parent_id, @root_transaction_id, @indexed_at
)

-- insertOrIgnoreWallet
INSERT INTO wallets (address, public_modulus)
VALUES (@address, @public_modulus)
Expand Down
18 changes: 11 additions & 7 deletions src/database/standalone-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function dataItemToDbRows(item: NormalizedDataItem, height?: number) {
tagValues,
newDataItemTags,
wallets,
newBundleDataItem: {
bundleDataItem: {
id,
parent_id: parentId,
root_transaction_id: rootTxId,
Expand Down Expand Up @@ -474,6 +474,8 @@ export class StandaloneSqliteDatabaseWorker {
this.stmts.bundles.insertOrIgnoreWallet.run(row);
}

this.stmts.bundles.insertBundleDataItem.run(rows.bundleDataItem);

this.stmts.bundles.upsertNewDataItem.run({
...rows.newDataItem,
height,
Expand Down Expand Up @@ -1371,9 +1373,10 @@ export class StandaloneSqliteDatabaseWorker {
fee: tx.reward,
quantity: tx.quantity,
dataSize: tx.data_size,
tags: tx.data_item_id.length > 1
? this.getGqlNewDataItemTags(tx.id)
: this.getGqlNewTransactionTags(tx.id),
tags:
tx.data_item_id.length > 1
? this.getGqlNewDataItemTags(tx.id)
: this.getGqlNewTransactionTags(tx.id),
contentType: tx.content_type,
blockIndepHash: toB64Url(tx.block_indep_hash),
blockTimestamp: tx.block_timestamp,
Expand Down Expand Up @@ -1479,9 +1482,10 @@ export class StandaloneSqliteDatabaseWorker {
fee: tx.reward,
quantity: tx.quantity,
dataSize: tx.data_size,
tags: tx.data_item_id.length > 1
? this.getGqlStableDataItemTags(tx.id)
: this.getGqlStableTransactionTags(tx.id),
tags:
tx.data_item_id.length > 1
? this.getGqlStableDataItemTags(tx.id)
: this.getGqlStableTransactionTags(tx.id),
contentType: tx.content_type,
blockIndepHash: toB64Url(tx.block_indep_hash),
blockTimestamp: tx.block_timestamp,
Expand Down

0 comments on commit f8eab58

Please sign in to comment.