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
Admin voting census original load (csv) #7591
Conversation
9306bb5
to
a2fc505
Compare
d3d3eff
to
75d6e51
Compare
61a2861
to
6de9af0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good job!! 👏 👏
}, | ||
visibility: "admin-only" | ||
) | ||
end | ||
|
||
def csv_rows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 I'm not sure about this, but maybe for very big files we need to do something like wc -l #{form.file.tempfile.path}
to avoid loading all the lines in the server memory. I have tested it with files of almost 2GB and it takes less than 2 seconds. I don't know if this is too hacky or if there is any better way to this but it would be nice to consider it. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it to what you suggest if it is more performant. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are okay we can work this and the increment counter out in another PR, so we don't block other PR's that depend on this one.
decidim-elections/app/controllers/decidim/votings/census/admin/census_controller.rb
Outdated
Show resolved
Hide resolved
decidim-elections/app/controllers/decidim/votings/census/admin/census_controller.rb
Outdated
Show resolved
Hide resolved
return broadcast(:invalid) unless dataset | ||
|
||
# rubocop:disable Rails/SkipsModelValidations | ||
Dataset.increment_counter(:csv_row_processed_count, dataset.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Even when I think this method is better, this could be faster if you do it directly in the CreateDatum command. I don't know if running a new command for each csv row could be a performance issue.
- Is this operation atomic? If we have several jobs running the same operation we could have race conditions problems. I saw that this is run in the
after_perform
part of the job, but I don't know exactly how it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First this was in the CreateDatum
command but as it updates the Dataset
model extracting it here seemed more appropriate.
In the future this command could be used to send an email when all_rows_processed?
.
On the other hand, I used the class method Dataset.increment_counter
instead of the instance method dataset.increment
for that reason according this post.
f784bf3
to
708e1b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! 👏🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Nothing much to add 😄
attributes = { | ||
hashed_in_person_data: form.hashed_in_person_data, | ||
hashed_check_data: form.hashed_check_data, | ||
|
||
full_name: form.full_name, | ||
full_address: form.full_address, | ||
postal_code: form.postal_code, | ||
mobile_phone_number: form.mobile_phone_number, | ||
email: form.email | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this but I think you can just call form.attributes
and it will return the same hash that you are building 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, is good to know this, but in this case the form has more attributes than the model because they are used to generate the hashed_*_data
attributes and those are not persisted.
8db8d80
to
87442de
Compare
…belongs_to voting. Apply review suggestions.
f2f12b8
to
1700d5f
Compare
* develop: fix: remove vote.js from elections manifest (#7795) Evote election log (#7757) Evote - identify with access code (#7740) Add unique trustee name (#7544) New translations en.yml (Finnish (plain)) (#7790) New Crowdin updates (#7754) Remove proposals dependency from the debates module (#7783) Make meetings functional without the proposals module (#7784) Make accountability functional without the proposals module (#7785) Make budgets functional without the proposals module (#7786) Remove BOM in CSV of private participants (#7781) Move searchlight gem to core and remove unnecessary requires (#7782) Admin voting census original load (csv) (#7591) Feat/evote count votes (#7769) Move votings answer results to its own table (#7767) Fix showing trustees menu on consultations module (#7778) Add missing assets to the elections manifest (#7773)
🎩 What? Why?
This PR adds the Census section to the voting administration panel. Where an admin user can upload a
.csv
file that will create aDataset
record and creates aCreateDatumJob
for each row/participant, some attributes are saved encrypted in the database and others the combination of attributes is hashed.📌 Related Issues
Testing
as an admin, go to admin > Votings > a voting in the space sidebar click on the Census entry.
Once in the
Census
section, select a csv file and submit the form.Once the file is submited, the admin is informed that the file is being processed:
📋 Checklist
🚨 Please review the guidelines for contributing to this repository.
docs/
.