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

#2350: Generate survey files async #2362

Merged
merged 46 commits into from
Dec 17, 2024

Conversation

anaPerezGhiglia
Copy link
Contributor

@anaPerezGhiglia anaPerezGhiglia commented Aug 5, 2024

Changes

  • create new SurveyResults GenServer
  • move responsibility of generating files from RespondentController to new SurveyResults actor
  • change files endpoints to "common" POST (without csv format)
  • change UI to make the POST call instead of a redirect to a new location

Out of scope

  • Keep track of generated files in the db
  • Files cleanup policy
  • Download existing files

for #2350

Screenshot 2024-11-28 at 5 42 54 PM

@matiasgarciaisaia matiasgarciaisaia force-pushed the feature/2350-survey-file-manager branch from c9ee306 to 02a9384 Compare August 15, 2024 22:42
@matiasgarciaisaia matiasgarciaisaia force-pushed the feature/2350-survey-file-manager branch from f08c2b8 to b633f1a Compare November 13, 2024 20:53
@matiasgarciaisaia matiasgarciaisaia marked this pull request as ready for review November 13, 2024 20:57
@matiasgarciaisaia
Copy link
Member

matiasgarciaisaia commented Nov 13, 2024

First of all, sorry for the huge PR. Things got wild.

Here's my list of pending things, which we may want to move to a different issue/PR.

  • Bug: not sending the filter to the file status request
  • Improve downloads modal UX (prevent generating a file that's being generated, show the user a file is currently being generated, add an exponential backoff to check the files status after triggering a file generation)
  • Filtered results files should consider the filter (ie, don't show a disposition:completed file if filtering for disposition:ready).
  • Check Survey state against pre-generated files (eg, don't offer to download a file from when the survey was running if it's already finished, maybe prevent regenerating files from finished surveys)
  • Only return status of files that the user can access (we're leaking some harmless info there - files can't be downloaded by unauthorized users)
  • Avoid concurrent fetchRespondentsFilesStatus calls
  • Fix skipped tests

I'll try to address some of these while we review the PR.

anaPerezGhiglia and others added 22 commits November 14, 2024 15:01
We should un-skip them by the end of the PR.

See #2350
The info about the generated files is still pending.

See #2350
This will allow us to check if there already is a file generated or not.

Also, we move the decision of whether to regenerate a file or not to the
user (instead of checking if we should generate the file again or not).

See #2350
From the UI, request that the CSV files are generated by the backend.

We still miss checking if the files exist or are currently being
generated.

See #2350
Small changes, nothing too relevant.

See #2350
There's probably still an issue with react-timeago not being properly
ignored yet.

See #2350
There are no definitions available.

See #2350
Thanks, eslint!

See #2350
They've already been solved or there's nothing to do about them.
They were previously placed in a public directory, statically served. We
now apply the usual access control we have for generation (and had for
streaming).

See #2350
Those URLs in the RespondentIndex.jsx smelled.

See #2350
Due to the way the `q` variable was bound in the previous
implementation of the `setInterval` call, we were always querying the
file status using the filter (or lack thereof) that was in place in the
first show of the modal.

We now get the current value of `q` at the time in which the refresh
function is called.

See #2350
They were already working - not sure when they were fixed but that's
fine.

See #2350
@matiasgarciaisaia matiasgarciaisaia force-pushed the feature/2350-survey-file-manager branch from a12192f to d5ceb9a Compare November 14, 2024 18:04
We were raising an exception instead.

See #2350
The URLs where broken when splitting generation and download.

See #2350
@matiasgarciaisaia matiasgarciaisaia force-pushed the feature/2350-survey-file-manager branch from 7aeabb7 to c9ba84b Compare November 14, 2024 20:43
@matiasgarciaisaia
Copy link
Member

matiasgarciaisaia commented Nov 28, 2024

  • Surveda won't manage old survey files (they'll pile up in the FS)
  • We should probably Docker-mount another volume/FS in the directory where the files are going to be generated in
  • Filtered results should honour the current filter (we're serving whichever filter we last generated). For this to work, filtered results should include filter in filename (beware special characters like : and ).

Copy link
Contributor Author

@anaPerezGhiglia anaPerezGhiglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot officially approve this PR since I was the original author, but this looks good to me! ✨
@matiasgarciaisaia I would encourage we deploy a preview of this branch to staging so we can play with it a bit without having to set it up in each of our local environments 😬

assets/js/actions/survey.js Outdated Show resolved Hide resolved

ActivityLog.download(project, conn, survey, "survey_results") |> Repo.insert()
ActivityLog.generate_file(project, conn, survey, "survey_results") |> Repo.insert()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the naming normalization perhaps we can change the ActivityLog entry to register respondents_results instead of survey_results

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the files themselves backwards-compatible. Changing these names would imply running a migration to change old activity logs from the DB. Which could be OK, but these are not exactly the same strings used "internally". We should also take a look at including the filter, somehow, for the results file - here we're completely ignoring whether there's a filter or not.


SurveyResults.generate_disposition_history_file(survey.id)

ActivityLog.generate_file(project, conn, survey, "disposition_history") |> Repo.insert()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we create en enum or constants with the different file names so we avoid repeating the strings all over?

lib/ask/survey_results.ex Outdated Show resolved Hide resolved
lib/ask/survey_results.ex Outdated Show resolved Hide resolved
lib/ask/survey_results.ex Outdated Show resolved Hide resolved
lib/ask/survey_results.ex Show resolved Hide resolved
lib/ask/survey_results.ex Show resolved Hide resolved
Without invalidating the timer, navigating from one survey to another
would keep the status for both surveys' files to be fetched, yielding
bugs in the UI.

See #2350
See #2362
Copy link
Contributor Author

@anaPerezGhiglia anaPerezGhiglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the last changes the files modal behaves as expected - even changing between different surveys. ✅
However, what I've noticed is that once the user opens the "download files" modal, the app keeps on requesting the /files status - even if the user has closed the modal. This is not critical, but it's useless. Even more because if the user opens the modal again, a new request is triggered

@matiasgarciaisaia
Copy link
Member

Yes. We don't have (or I haven't found) an event for when the modal closes, so the requests keep going every 20 seconds even when we don't need them.

@matiasgarciaisaia matiasgarciaisaia merged commit d1b78b1 into main Dec 17, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants