Skip to content

Commit 3f4a4fc

Browse files
committed
fix: use deterministic order for AND tag ops
1 parent d320041 commit 3f4a4fc

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/repo/postgres.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
use std::ops::Deref;
21
use crate::db::QueryResult;
2+
use crate::error;
33
use crate::error::Result;
44
use crate::event::{single_char_tagname, Event};
55
use crate::nip05::{Nip05Name, VerificationRecord};
66
use crate::payment::{InvoiceInfo, InvoiceStatus};
7+
use crate::repo::postgres_migration::run_migrations;
78
use crate::repo::{now_jitter, NostrRepo};
9+
use crate::server::NostrMetrics;
810
use crate::subscription::{ReqFilter, Subscription, TagOperand};
11+
use crate::utils::{self, is_hex, is_lower_hex};
912
use async_std::stream::StreamExt;
1013
use async_trait::async_trait;
1114
use chrono::{DateTime, TimeZone, Utc};
15+
use itertools::Itertools;
16+
use nostr::key::Keys;
1217
use sqlx::postgres::PgRow;
1318
use sqlx::Error::RowNotFound;
1419
use sqlx::{Error, Execute, FromRow, Postgres, QueryBuilder, Row};
20+
use std::ops::Deref;
1521
use std::time::{Duration, Instant};
16-
use itertools::Itertools;
17-
use crate::error;
18-
use crate::repo::postgres_migration::run_migrations;
19-
use crate::server::NostrMetrics;
20-
use crate::utils::{self, is_hex, is_lower_hex};
21-
use nostr::key::Keys;
2222
use tokio::sync::mpsc::Sender;
2323
use tokio::sync::oneshot::Receiver;
2424
use tracing::{debug, error, info, trace, warn};
@@ -765,7 +765,9 @@ fn query_from_filter(f: &'_ ReqFilter) -> Option<QueryBuilder<'_, Postgres>> {
765765
tag_ctr += 1;
766766
query.push("))");
767767
} else if let TagOperand::And(v_and) = val {
768-
for vx in v_and.iter() {
768+
let mut sorted_values: Vec<_> = v_and.iter().collect();
769+
sorted_values.sort();
770+
for vx in sorted_values {
769771
query
770772
.push(format!(
771773
" JOIN \"tag\" t{0} on e.id = t{0}.event_id AND t{0}.\"name\" = ",

0 commit comments

Comments
 (0)