Skip to content

Commit

Permalink
Add additional order_by query to get predictable results
Browse files Browse the repository at this point in the history
  • Loading branch information
cayb0rg committed Feb 1, 2024
1 parent 6e1bf19 commit 0c9200e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions fuel/app/classes/materia/api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,11 @@ static public function users_search($input, $page_number = 0)
$offset = $items_per_page * $page_number;

// query DB for only a single page + 1 item
$displayable_items = \Model_User::find_by_name_search($input, $offset, $items_per_page);
$displayable_items = \Model_User::find_by_name_search($input, $offset, $items_per_page + 1);

$has_next_page = sizeof($displayable_items) > ($items_per_page - 1) ? true : false;
$has_next_page = sizeof($displayable_items) > $items_per_page ? true : false;

if ($has_next_page) array_pop($displayable_items);

foreach ($displayable_items as $key => $person)
{
Expand Down
20 changes: 14 additions & 6 deletions fuel/app/classes/materia/widget/instance/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static public function get_all(Array $inst_ids, $load_qset=false, $timestamp=fal
->from('widget_instance')
->where('id', 'IN', $inst_ids)
->and_where('is_deleted', '=', $deleted ? '1' : '0')
->order_by('created_at', 'desc')
->order_by('id', 'desc')
->offset("$offset")
->limit("$limit")
->execute()
Expand Down Expand Up @@ -85,10 +87,12 @@ public static function get_paginated_instances_for_user($user_id, $page_number =
$offset = $items_per_page * $page_number;

// query DB for only a single page of instances + 1
$displayable_items = self::get_all($inst_ids, false, false, false, $offset, $items_per_page);
$displayable_items = self::get_all($inst_ids, false, false, false, $offset, $items_per_page + 1);

// if the returned number of instances is greater than a page, there's more pages
$has_next_page = sizeof($displayable_items) > ($items_per_page - 1) ? true : false;
$has_next_page = sizeof($displayable_items) > $items_per_page ? true : false;

if ($has_next_page) array_pop($displayable_items);

$data = [
'pagination' => $displayable_items
Expand Down Expand Up @@ -151,10 +155,12 @@ public static function get_paginated_instance_search(string $input, $page_number
$offset = $items_per_page * $page_number;

// query DB for only a single page of instances + 1
$displayable_items = self::get_widget_instance_search($input, $offset, $items_per_page);
$displayable_items = self::get_widget_instance_search($input, $offset, $items_per_page + 1);

// if the returned number of instances is greater than a page, there's more pages
$has_next_page = sizeof($displayable_items) > ($items_per_page - 1) ? true : false;
$has_next_page = sizeof($displayable_items) > $items_per_page ? true : false;

if ($has_next_page) array_pop($displayable_items);

$data = [
'pagination' => $displayable_items,
Expand All @@ -180,8 +186,10 @@ public static function get_widget_instance_search(string $input, int $offset = 0
->from('widget_instance')
->where('id', 'LIKE', "%$input%")
->or_where('name', 'LIKE', "%$input%")
->limit("$limit")
->offset("$offset")
->order_by('created_at', 'desc')
->order_by('id', 'desc')
->offset($offset)
->limit($limit)
->execute()
->as_array();

Expand Down
2 changes: 1 addition & 1 deletion src/components/include.scss
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ header {
background-color: #ffffff;
padding: 0;
position: absolute;
bottom: -150%;
bottom: -140%;
left: -10px;
border-left: 1px solid #d3d3d3;
border-right: 1px solid #d3d3d3;
Expand Down

0 comments on commit 0c9200e

Please sign in to comment.