Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: query tx by time. #269

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@

<h3 id="1.2">1.2 获取交易列表</h3>

| 参数 | 类型 | 必传 | 说明 |
|-----------|--------|----|------------|
| from | string | N | 发送者 |
| to | string | N | 接收者 |
| ty | number | N | 类型 |
| page | number | N | 页码,缺省值为1 |
| page_size | number | N | 页大小,缺省值为10 |
| 参数 | 类型 | 必传 | 说明 |
|------------|--------|----|------------|
| from | string | N | 发送者 |
| to | string | N | 接收者 |
| ty | number | N | 类型 |
| start_time | number | N | 开始时间戳 |
| end_time | number | N | 结束时间戳 |
| page | number | N | 页码,缺省值为1 |
| page_size | number | N | 页大小,缺省值为10 |

* Request: `/api/txs?page=2&page_size=2`
* Response:
Expand Down
8 changes: 8 additions & 0 deletions explorer/src/service/v2/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct GetTxsParams {
pub from: Option<String>,
pub to: Option<String>,
pub ty: Option<i32>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
pub page: Option<i32>,
pub page_size: Option<i32>,
}
Expand All @@ -40,6 +42,12 @@ pub async fn get_txs(
if let Some(ty) = params.ty {
query_params.push(format!("ty={} ", ty));
}
if let Some(start_time) = params.start_time {
query_params.push(format!("timestamp>={} ", start_time));
}
if let Some(end_time) = params.end_time {
query_params.push(format!("timestamp<={} ", end_time));
}
if !query_params.is_empty() {
sql_query = sql_query
.add("WHERE ")
Expand Down
Loading