Adds a simple query to the count filter
This commit is contained in:
+29
-4
@@ -117,6 +117,7 @@ class QueryBuilder(
|
|||||||
|
|
||||||
if (newFilter.isSimpleQuery()) {
|
if (newFilter.isSimpleQuery()) {
|
||||||
return makeSimpleQuery(
|
return makeSimpleQuery(
|
||||||
|
project = true,
|
||||||
ids = newFilter.ids,
|
ids = newFilter.ids,
|
||||||
authors = newFilter.authors,
|
authors = newFilter.authors,
|
||||||
kinds = newFilter.kinds,
|
kinds = newFilter.kinds,
|
||||||
@@ -250,6 +251,23 @@ class QueryBuilder(
|
|||||||
filter: Filter,
|
filter: Filter,
|
||||||
db: SQLiteDatabase,
|
db: SQLiteDatabase,
|
||||||
): Int {
|
): Int {
|
||||||
|
val newFilter = filter.toFilterWithDTags()
|
||||||
|
|
||||||
|
if (newFilter.isSimpleQuery()) {
|
||||||
|
val sql =
|
||||||
|
makeSimpleQuery(
|
||||||
|
project = false,
|
||||||
|
ids = newFilter.ids,
|
||||||
|
authors = newFilter.authors,
|
||||||
|
kinds = newFilter.kinds,
|
||||||
|
dTags = newFilter.dTags,
|
||||||
|
since = newFilter.since,
|
||||||
|
until = newFilter.until,
|
||||||
|
limit = newFilter.limit,
|
||||||
|
)
|
||||||
|
return db.runCount(sql.sql, sql.args)
|
||||||
|
}
|
||||||
|
|
||||||
val rowIdSubQuery = prepareRowIDSubQueries(filter, hasher(db))
|
val rowIdSubQuery = prepareRowIDSubQueries(filter, hasher(db))
|
||||||
|
|
||||||
return if (rowIdSubQuery == null) {
|
return if (rowIdSubQuery == null) {
|
||||||
@@ -589,6 +607,7 @@ class QueryBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun makeSimpleQuery(
|
private fun makeSimpleQuery(
|
||||||
|
project: Boolean,
|
||||||
ids: List<HexKey>? = null,
|
ids: List<HexKey>? = null,
|
||||||
authors: List<HexKey>? = null,
|
authors: List<HexKey>? = null,
|
||||||
kinds: List<Kind>? = null,
|
kinds: List<Kind>? = null,
|
||||||
@@ -624,14 +643,20 @@ class QueryBuilder(
|
|||||||
|
|
||||||
val sql =
|
val sql =
|
||||||
buildString {
|
buildString {
|
||||||
append("SELECT id, pubkey, created_at, kind, tags, content, sig FROM event_headers")
|
if (project) {
|
||||||
|
append("SELECT id, pubkey, created_at, kind, tags, content, sig FROM event_headers")
|
||||||
|
} else {
|
||||||
|
append("SELECT count(*) FROM event_headers")
|
||||||
|
}
|
||||||
if (clause.conditions.isNotEmpty()) {
|
if (clause.conditions.isNotEmpty()) {
|
||||||
append("\nWHERE ")
|
append("\nWHERE ")
|
||||||
append(clause.conditions)
|
append(clause.conditions)
|
||||||
}
|
}
|
||||||
append("\nORDER BY created_at DESC")
|
if (project) {
|
||||||
if (indexStrategy.useAndIndexIdOnOrderBy) {
|
append("\nORDER BY created_at DESC")
|
||||||
append(", event_headers.id ASC")
|
if (indexStrategy.useAndIndexIdOnOrderBy) {
|
||||||
|
append(", event_headers.id ASC")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
append("\nLIMIT ")
|
append("\nLIMIT ")
|
||||||
|
|||||||
Reference in New Issue
Block a user