Skip to content

Commit 3d68e50

Browse files
committed
improve sql: script_exists_in_output.
1 parent 9178c0e commit 3d68e50

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

util/indexer-r/src/indexer/remove.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,35 @@ async fn script_exists_in_output(
193193
script_id: i64,
194194
tx: &mut Transaction<'_, Any>,
195195
) -> Result<bool, Error> {
196-
let row = sqlx::query(
196+
let row_lock = sqlx::query(
197197
r#"
198198
SELECT EXISTS (
199199
SELECT 1
200200
FROM output
201-
WHERE lock_script_id = $1 OR type_script_id = $1
201+
WHERE lock_script_id = $1
202202
)
203203
"#,
204204
)
205205
.bind(script_id)
206-
.fetch_one(tx)
206+
.fetch_one(&mut *tx)
207207
.await
208208
.map_err(|err| Error::DB(err.to_string()))?;
209209

210-
Ok(row.get::<bool, _>(0))
210+
let row_type = sqlx::query(
211+
r#"
212+
SELECT EXISTS (
213+
SELECT 1
214+
FROM output
215+
WHERE type_script_id = $1
216+
)
217+
"#,
218+
)
219+
.bind(script_id)
220+
.fetch_one(&mut *tx)
221+
.await
222+
.map_err(|err| Error::DB(err.to_string()))?;
223+
224+
Ok(row_lock.get::<bool, _>(0) || row_type.get::<bool, _>(0))
211225
}
212226

213227
async fn uncle_exists_in_association_table(

0 commit comments

Comments
 (0)