Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Let's use streams #510

Closed
dgrammatiko opened this issue Feb 8, 2018 · 7 comments
Closed

Let's use streams #510

dgrammatiko opened this issue Feb 8, 2018 · 7 comments

Comments

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Feb 8, 2018

Possible solution instead of implementing pagination

Stream what?

So right now whenever a call from the from end is done to get the json for the items (files) in a directory the process is like: server reads the files -> creates the appropriate json -> sents back the json. Using stream we can have this process asynchronous, meaning that instead of waiting to get the complete json we could start decoding the stream and build the json (the front end store data) as the data is streamed from the backend, almost realtime. Now if we combine this with some clever lasyloading (intersection observer) then we will end up with the exact behaviour that google has in their search images page! WIN

What we need?

Three parts need to come together here:

@schnuti
Copy link
Collaborator

schnuti commented Feb 8, 2018

Don't you first need some sized images? i.e. thumbs. As I understand it, the search engines do not send the original sizes. I have no clue how the browser and the client stores the data but I have a feeling that there is a limit somewhere.

@dgrammatiko
Copy link
Contributor Author

We already have the functionality for the thumbs (or at least that's my impression)

@schnuti
Copy link
Collaborator

schnuti commented Feb 8, 2018

And I have another impression see #475 and my own #255 and after checking the background images size.

800px_cradle_mountain_seen_from_barn_bluff.jpg is in real on disc a 500x375 image and that's the size of the background image.

@laoneo laoneo added the feature label Feb 9, 2018
@laoneo laoneo added this to the Backlog milestone Feb 9, 2018
@laoneo
Copy link
Contributor

laoneo commented Feb 9, 2018

Sounds a nice approach. From a quick glance, not sure what it has for influence to the API. Will it still work as before and the streams are an addition on the top or will the API change by itself?

@dgrammatiko
Copy link
Contributor Author

I guess the getFiles() part needs some refactoring to :

$iterator = function () {
    foreach (new DirectoryIterator(__DIR__) as $file) {
        yield $file->getFilename();
    }
};

$encoder = (new \Violet\StreamingJsonEncoder\BufferJsonEncoder($iterator))->setOptions(JSON_PRETTY_PRINT);

$stream = new \Violet\StreamingJsonEncoder\JsonStream($encoder);
}

@laoneo
Copy link
Contributor

laoneo commented Mar 9, 2018

Can this lead to conflicts with #175 then?

@dgrammatiko
Copy link
Contributor Author

I don't see any problem, eg if you search for someFilename the back end will stream something (with some value in the json if the file exists or nothing if the file doesn't exist) so the end result result will be the same json the backend could throw if it wasn't streamed. Maybe the implementation of the search might be slightly different in the front end (code wise) but nothing too radical or too special. Unless I'm missing something crucial here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants