Skip to content

Remove mut vec #605

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

Merged
merged 4 commits into from
Mar 8, 2017
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
11 changes: 5 additions & 6 deletions src/bin/fill-in-user-id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ struct GithubUser {
}

fn update(app: &App, tx: &postgres::transaction::Transaction) {
let mut rows = Vec::new();
let query = "SELECT id, gh_login, gh_access_token, gh_avatar FROM users \
WHERE gh_id IS NULL";
for row in &tx.query(query, &[]).unwrap() {
let query = "SELECT id, gh_login, gh_access_token, gh_avatar FROM users
WHERE gh_id IS NULL";
let rows = tx.query(query, &[]).unwrap().into_iter().map(|row| {
let id: i32 = row.get("id");
let login: String = row.get("gh_login");
let token: String = row.get("gh_access_token");
let avatar: Option<String> = row.get("gh_avatar");
rows.push((id, login, http::token(token), avatar));
}
(id, login, http::token(token), avatar)
}).collect::<Vec<_>>();

for (id, login, token, avatar) in rows {
println!("attempt: {}/{}", id, login);
Expand Down
17 changes: 7 additions & 10 deletions src/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,9 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
WHERE date > $1
AND version_id = ANY($2)
ORDER BY date ASC")?;
let mut downloads = Vec::new();
for row in stmt.query(&[&cutoff_date, &ids])?.iter() {
let download: VersionDownload = Model::from_row(&row);
downloads.push(download.encodable());
}
let downloads = stmt.query(&[&cutoff_date, &ids])?.iter().map(|row| {
VersionDownload::from_row(&row).encodable()
}).collect::<Vec<_>>();

let stmt = tx.prepare("\
SELECT COALESCE(to_char(DATE(version_downloads.date), 'YYYY-MM-DD'), '') AS date,
Expand All @@ -1032,13 +1030,12 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
AND versions.id != ALL($3)
GROUP BY DATE(version_downloads.date)
ORDER BY DATE(version_downloads.date) ASC")?;
let mut extra = Vec::new();
for row in stmt.query(&[&cutoff_date, &krate.id, &ids])?.iter() {
extra.push(ExtraDownload {
let extra = stmt.query(&[&cutoff_date, &krate.id, &ids])?.iter().map(|row| {
ExtraDownload {
downloads: row.get("downloads"),
date: row.get("date")
});
}
}
}).collect::<Vec<_>>();

#[derive(RustcEncodable)]
struct ExtraDownload { date: String, downloads: i64 }
Expand Down
8 changes: 3 additions & 5 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,9 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
let stmt = tx.prepare("SELECT * FROM version_downloads
WHERE date > $1 AND version_id = $2
ORDER BY date ASC")?;
let mut downloads = Vec::new();
for row in stmt.query(&[&cutoff_date, &version.id])?.iter() {
let download: VersionDownload = Model::from_row(&row);
downloads.push(download.encodable());
}
let downloads = stmt.query(&[&cutoff_date, &version.id])?.iter().map(|row| {
VersionDownload::from_row(&row).encodable()
}).collect();

#[derive(RustcEncodable)]
struct R { version_downloads: Vec<EncodableVersionDownload> }
Expand Down