-
-
Notifications
You must be signed in to change notification settings - Fork 815
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
tec: Refactor the export feature #3045
tec: Refactor the export feature #3045
Conversation
Even if the issue FreshRSS#3035 seemed pretty simple at a first glance, it was more complicated than I expected. Because we send CSP headers AFTER running the controller actions, it means we can't "echo" any content from the controller. It's in fact a good practice, but it was easier at the time we developed the feature. To fix that, the only thing I had to do was to move the `print()` and `readfile()` function into the view. The problem was that we needed to output the content from the CLI too. Then, things became more complicated. I decided to extract the export-related methods in a `FreshRSS_Export_Service` class, in order to use it from both the controller and the CLI. It was an opportunity to refactor the whole feature in order to make it a bit more linear and easy to read. Reference: FreshRSS#3035
@@ -720,76 +720,6 @@ private function addFeedJson($origin) { | |||
return $return; |
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.
The diff concerning this file is a bit complicated to review, I suggest to only read the new file
return [ | ||
"feeds_{$day}.opml.xml", | ||
$view->helperToString('export/opml') | ||
]; |
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 completely happy with this pattern (i.e. returning an array containing the filename and the content) but it makes the things easier in the controller and the cli
$type, '', FreshRSS_Entry::STATE_ALL, 'ASC', -1 | ||
); | ||
$view->entryIdsTagNames = $this->tag_dao->getEntryIdsTagNames($view->entriesId); | ||
// The following is a streamable query, i.e. must be last |
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 kept this comment line, but I didn't understand its meaning
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.
It could be reworded :-P
We cannot have two streamed SQL requests on the same DB connection at the same time
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.
No it's fine, it's just that I wasn't able to spot the difference between this method and the others. But I just realize that fetchAll()
isn't called, and I didn't know that PDOStatement
implemented the Traversable
interface
@@ -0,0 +1 @@ | |||
<?= $this->content ?> |
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.
This is the real fix of #3035 :)
Minz_Request::param('export_starred', false), | ||
Minz_Request::param('export_labelled', false), | ||
Minz_Request::param('export_feeds', array()) | ||
return Minz_Request::forward( |
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 just remembered I forgot to explain these return
. It's actually useless because the forward(..., true)
will immediately trigger a redirection, but it's implicit and not clear for a new developer. I suggest we start to put explicit return
when we want the method to stop, 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.
Yes, that sounds good indeed
Looks good.
docker exec --user www-data freshrss cli/export-zip-for-user.php --user alex
FreshRSS exporting ZIP for user “alex”…
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 290816 bytes) in /var/www/FreshRSS/app/Services/ExportService.php on line 175
|
Do you mean the |
Yes @marienfressinaud , this is what I mean. I did not check and - due to the memory problem I observed - assumed there was no default limit through the CLI. Now that we have the SQLite export (which uses streams), the ZIP export is less relevant, but I do not like the fact that it uses so much memory and crashes even for light exports. This might be out of scope for this PR though |
Suggestion for future work:
|
Closes #3035
Changes proposed in this pull request:
Even if the issue #3035 seemed pretty simple at a first glance, it was
more complicated than I expected. Because we send CSP headers AFTER
running the controller actions, it means we can't "echo" any content
from the controller. It's in fact a good practice, but it was easier at
the time we developed the feature.
To fix that, the only thing I had to do was to move the
print()
andreadfile()
function into the view. The problem was that we needed tooutput the content from the CLI too. Then, things became more
complicated. I decided to extract the export-related methods in a
FreshRSS_Export_Service
class, in order to use it from both thecontroller and the CLI. It was an opportunity to refactor the whole
feature in order to make it a bit more linear and easy to read.
How to test the feature manually:
php cli/export-zip-for-user.php
andphp cli/export-opml-for-user.php
commandsPull request checklist:
Additional information can be found in the documentation.