Skip to content

Commit

Permalink
Merge branch 'develop' into twitter-urls-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rowasc committed Apr 20, 2020
2 parents bf7598e + 3037be1 commit 3241f62
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Expand Up @@ -121,6 +121,14 @@ The latest releases of the Ushahidi Platform come with a little handy tool calle

If something is wrong, this tool may provide you with useful information about what exactly seems to be the cause.

## Connecting the mobile app

Please note that the mobile app relies on the contents of the "config.json" file in order to connect to the API backend.

In order to help the app find the backend, ensure that the key `backend_url` in the JSON file is set appropriately to the absolute public URL of your deployment \(i.e. `"backend_url": "https://example.deployment.com"` \)

If you are running the Docker container, you may set this variable using the `SITE_URL` environment variable. \(In the default install the site URL **is** the backend URL\).

## Queue drivers \(and "sync" driver issues\)

The Ushahidi Platform API uses a queue system for running some end-user requested operations in the background. At the moment of this writing, such operations are CSV importing and exporting. More may come up in the future.
Expand Down
33 changes: 26 additions & 7 deletions src/App/Repository/PostRepository.php
Expand Up @@ -35,7 +35,9 @@
use Ushahidi\App\Multisite\OhanzeeResolver;
use Ushahidi\Core\Tool\Permissions\InteractsWithPostPermissions;

use Illuminate\Support\Collection;
use League\Event\ListenerInterface;

use Ushahidi\Core\Traits\Event;

class PostRepository extends OhanzeeRepository implements
Expand Down Expand Up @@ -249,13 +251,30 @@ public function getEntity(array $data = null): Post
/* Check which types are used in the form */
$form_attributes = $this->form_attributes_by_form->get(intval($data['form_id']));
if ($form_attributes) {
$types_to_fetch = $form_attributes
->pluck('type')
->unique()
->toArray();

/* Intersect with requested types, subtract types already provided in $data */
$types_to_fetch = array_intersect($types_to_fetch, $this->include_value_types);
/* Count how many of each form attribute type we have */
$types_to_fetch_with_attribute_count = $form_attributes
->groupBy('type')
->map(function ($attrs) {
return $attrs->count();
});

$types_to_fetch = $types_to_fetch_with_attribute_count->keys()->toArray();

/* Intersect with requested types */
if (count($this->include_value_types) > 0) {
$types_to_fetch = array_intersect($types_to_fetch, $this->include_value_types);
}

/* drop types that we have already fetched
BUT only if there is a SINGLE attribute of that type in the form,
since the SQL JOINs that we have run previously are only good for fetching
a SINGLE value of each type for each post.
If we don't do this, we would be leaving out the values of the second
and subsequent attributes defined with that type */
$already_obtained_types = collect($already_obtained_types)
->filter(function ($type) use ($types_to_fetch_with_attribute_count) {
return $types_to_fetch_with_attribute_count->get($type) < 2;
})->toArray();
$types_to_fetch = array_diff($types_to_fetch, $already_obtained_types);
}
}
Expand Down

0 comments on commit 3241f62

Please sign in to comment.