@@ -39,14 +39,15 @@ async function getSearchResults(
3939 certificate_sha256,
4040 log_id,
4141 log_index,
42+ entry_timestamp,
4243 not_after,
4344 subject_common_name,
4445 issuer_common_name,
4546 issuer_organization
4647 FROM ct_log_entries_by_name
4748 WHERE name_rev = reverse({query:String}) OR
4849 name_rev LIKE reverse({wildcard:String})
49- ORDER BY not_after DESC
50+ ORDER BY entry_timestamp DESC
5051 LIMIT {limit:UInt32}
5152 SETTINGS max_execution_time = 10, max_threads = 1, max_memory_usage = 134217728` ;
5253 additionalParams . wildcard = `%.${ query } ` ;
@@ -71,6 +72,7 @@ async function getSearchResults(
7172 certificate_sha256,
7273 not_before,
7374 not_after,
75+ entry_timestamp,
7476 subject_common_name,
7577 issuer_common_name,
7678 issuer_organization,
@@ -79,7 +81,7 @@ async function getSearchResults(
7981 FROM ct_log_entries
8082 WHERE ${ whereClause }
8183 AND entry_type = 'x509_entry'
82- ORDER BY not_after DESC
84+ ORDER BY entry_timestamp DESC
8385 LIMIT {limit:UInt32}
8486 SETTINGS max_execution_time = 10, max_threads = 1, max_memory_usage = 134217728
8587 ` ;
@@ -110,6 +112,10 @@ async function getSearchResults(
110112
111113 if ( certMap . has ( sha256 ) ) {
112114 // Add this log entry to the existing certificate
115+ const existing = certMap . get ( sha256 ) ! ;
116+ if ( current . entry_timestamp < existing . cert . entry_timestamp ) {
117+ existing . cert . entry_timestamp = current . entry_timestamp ;
118+ }
113119 certMap . get ( sha256 ) ! . logEntries . add ( logKey ) ;
114120 } else {
115121 // Create new entry
@@ -125,6 +131,11 @@ async function getSearchResults(
125131 ...cert ,
126132 ct_log_count : logEntries . size ,
127133 } ) ) ;
134+ data . sort (
135+ ( a , b ) =>
136+ new Date ( b . entry_timestamp ) . getTime ( ) -
137+ new Date ( a . entry_timestamp ) . getTime ( ) ,
138+ ) ;
128139
129140 const headers = resultSet . response_headers ;
130141 const summaryHeader = headers [ "x-clickhouse-summary" ] ;
0 commit comments