Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feature/latest_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Feb 21, 2024
2 parents 67dcb7e + c953c34 commit a692a03
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
60 changes: 60 additions & 0 deletions contracts/warp-controller/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ pub fn query_jobs(deps: Deps, env: Env, data: QueryJobsMsg) -> StdResult<JobsRes
job_status,
..
} => query_jobs_by_ids(deps, env, ids, job_status),
QueryJobsMsg {
active: _,
name,
owner: Some(owner),
job_status,
start_after,
limit: _,
..
} => query_jobs_by_owner(
deps,
env,
name,
owner,
job_status,
start_after.map(|i| (i._1.u64())),
page_size as usize,
),
QueryJobsMsg {
active: _,
name,
Expand Down Expand Up @@ -130,3 +147,46 @@ pub fn query_jobs_by_reward(
total_count: infos.len() as u32,
})
}

pub fn query_jobs_by_owner(
deps: Deps,
env: Env,
name: Option<String>,
owner: Addr,
job_status: Option<JobStatus>,
start_after: Option<u64>,
limit: usize,
) -> StdResult<JobsResponse> {
let start = start_after.map(Bound::exclusive);
let map = if job_status.is_some() && job_status.clone().unwrap() != JobStatus::Pending {
FINISHED_JOBS()
} else {
PENDING_JOBS()
};
let infos = map
.idx
.owner
.prefix(owner.to_string())
.range(deps.storage, start, None, Order::Ascending)
.filter(|h| {
resolve_filters(
deps,
env.clone(),
h.as_ref().unwrap().clone().1,
name.clone(),
None,
job_status.clone(),
)
})
.take(limit)
.collect::<StdResult<Vec<_>>>()?;

let mut jobs = vec![];
for info in infos.clone() {
jobs.push(info.1);
}
Ok(JobsResponse {
jobs,
total_count: infos.len(),

Check failure on line 190 in contracts/warp-controller/src/query/job.rs

View workflow job for this annotation

GitHub Actions / Test

mismatched types

Check failure on line 190 in contracts/warp-controller/src/query/job.rs

View workflow job for this annotation

GitHub Actions / Lint

mismatched types
})
}
13 changes: 12 additions & 1 deletion contracts/warp-controller/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use crate::ContractError;
pub struct JobIndexes<'a> {
pub reward: UniqueIndex<'a, (u128, u64), Job>,
pub publish_time: MultiIndex<'a, u64, Job, u64>,
pub owner: MultiIndex<'a, String, Job, u64>,
}

impl IndexList<Job> for JobIndexes<'_> {
fn get_indexes(&'_ self) -> Box<dyn Iterator<Item = &'_ dyn Index<Job>> + '_> {
let v: Vec<&dyn Index<Job>> = vec![&self.reward, &self.publish_time];
let v: Vec<&dyn Index<Job>> = vec![&self.reward, &self.publish_time, &self.owner];
Box::new(v.into_iter())
}
}
Expand All @@ -32,6 +33,11 @@ pub fn PENDING_JOBS<'a>() -> IndexedMap<'a, u64, Job, JobIndexes<'a>> {
"pending_jobs_v6",
"pending_jobs__publish_timestamp_v6",
),
owner: MultiIndex::new(
|_pk, job| job.owner.to_string(),
"pending_jobs_v6",
"pending_jobs__owner_v6",
),
};
IndexedMap::new("pending_jobs_v6", indexes)
}
Expand All @@ -48,6 +54,11 @@ pub fn FINISHED_JOBS<'a>() -> IndexedMap<'a, u64, Job, JobIndexes<'a>> {
"finished_jobs_v6",
"finished_jobs__publish_timestamp_v6",
),
owner: MultiIndex::new(
|_pk, job| job.owner.to_string(),
"finished_jobs_v6",
"finished_jobs__owner_v6",
),
};
IndexedMap::new("finished_jobs_v6", indexes)
}
Expand Down

0 comments on commit a692a03

Please sign in to comment.