Skip to content

Commit

Permalink
fix timestamp reqs patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kutsenko committed May 12, 2022
1 parent 9f65364 commit 699618c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 1 addition & 0 deletions migrations/2021-10-19-121919_init_tables/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE INDEX IF NOT EXISTS blocks_microblocks_time_stamp_uid_idx ON blocks_micro
CREATE INDEX IF NOT EXISTS blocks_microblocks_is_solidified_idx ON blocks_microblocks(is_solidified) where is_solidified = false;
CREATE INDEX IF NOT EXISTS block_microblocks_timestamp_uid ON blocks_microblocks (to_timestamp(time_stamp/1000) desc, uid desc);
CREATE INDEX IF NOT EXISTS block_microblocks_uid_height ON blocks_microblocks (uid desc, height);
CREATE INDEX IF NOT EXISTS blocks_mblocks_uid_stamp_part ON blocks_microblocks(uid desc, to_timestamp(time_stamp / 1000) desc) where is_solidified;

CREATE TABLE safe_heights (
uid BIGINT GENERATED BY DEFAULT AS IDENTITY CONSTRAINT safe_heights_uid_pkey PRIMARY KEY,
Expand Down
5 changes: 1 addition & 4 deletions src/lib/api/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pub async fn get_uids_from_req(
params: &HashMap<String, String>,
) -> Result<i64, AppError> {
let mut sql: UidsQuery = UidsQuery::None;
dbg!(&params);

match params.get("height".into()) {
Some(v) => {
Expand All @@ -82,8 +81,7 @@ pub async fn get_uids_from_req(
Some(t) => {
let tt: Result<DateTime<Utc>, _> = t.parse();
if tt.is_ok() {
sql = UidsQuery::ByTimestamp("select uid from blocks_microblocks where to_timestamp(time_stamp/1000) <= $1 order by uid desc limit 1", tt.unwrap());
dbg!(&sql);
sql = UidsQuery::ByTimestamp("select uid from blocks_microblocks where to_timestamp(time_stamp/1000) <= $1 and is_solidified order by uid desc limit 1", tt.unwrap());
} else {
return Err(AppError::InvalidQueryString("invalid timestamp".into()));
}
Expand Down Expand Up @@ -116,7 +114,6 @@ pub async fn get_uids_from_req(

if rows.len() > 0 {
let uid = rows[0].get::<'_, _, i64>(0);
dbg!(&uid);
return Ok(uid);
}

Expand Down

0 comments on commit 699618c

Please sign in to comment.