Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
//Cache for autocompleting Keywords field in Catalog Advanced Search
define('CACHE_DIR', '../application/cache/');
define('KEYWORDS_CACHE_FILENAME', 'keywords_cache.txt');
define('KEYWORDS_CACHE_KEY_APCU', 'keywords_cache');

/* End of file constants.php */
/* Location: ./application/config/constants.php */
2 changes: 1 addition & 1 deletion application/config/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

$config['migration_enabled'] = TRUE;
$config['migration_type'] = 'sequential';
$config['migration_version'] = 5;
$config['migration_version'] = 4;
$config['migration_path'] = APPPATH . 'migrations/';
22 changes: 0 additions & 22 deletions application/controllers/cron/Keywords_cache_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,7 @@ public function update_cache()
$query = $this->db->query($sql);
$json_encoded_keywords_cache = json_encode($query->result_array());

// Use following two lines for file-based cache.
// If using file-based cache, make sure that autocomplete() function in
// application/models/Keyword_model.php is also using file-based caching

$this->load->helper('file');
write_file(CACHE_DIR . KEYWORDS_CACHE_FILENAME, $json_encoded_keywords_cache);

/**
// Use following for apcu cache.
// If using apcu cache, make sure that autocomplete() function in
// application/models/Keyword_model.php is also using apcu caching

if (apcu_exists(KEYWORDS_CACHE_KEY_APCU))
{
// overwrite existing data for this key
apcu_store(KEYWORDS_CACHE_KEY_APCU, $json_encoded_keywords_cache);
}
else
{
// must use apcu_add if key not already present in cache
apcu_add(KEYWORDS_CACHE_KEY_APCU, $json_encoded_keywords_cache);
}
**/

}
}
34 changes: 0 additions & 34 deletions application/migrations/005_write_keywords_initial_cache.php

This file was deleted.

70 changes: 1 addition & 69 deletions application/models/Keyword_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,7 @@ public function get_applied($list_keywords)

}

/**
public function get_all_keywords_used_in_projects()
{
error_log("In get_all_ keywords_used_in_project");
$sql = 'SELECT DISTINCT k.value
FROM keywords k
JOIN project_keywords pk
ON k.id = pk.keyword_id';

$query = $this->db->query($sql);
return $query->result_array();
}

**/

public function autocomplete($term)
public function autocomplete($term)
{
// To minimise the number of database calls in our system if multiple
// users are entering values in the Advanced Search Keywords field at the
Expand All @@ -36,18 +21,9 @@ public function autocomplete($term)
$json_encoded_keywords_cache_as_read_from_file = '';
$cached_result_array = array();

// Use following two lines for file-based cache.
// If using file-based cache, make sure that /application/controllers/cron/Keywords_cache_update
// is writing a file-based cache
$this->load->helper('file');
$json_encoded_keywords_cache = read_file(CACHE_DIR . KEYWORDS_CACHE_FILENAME);

// Use following line for apcu cache.
// If using apcu cache, make sure that /application/controllers/cron/Keywords_cache_update
// is writing to apcu cache

// $json_encoded_keywords_cache = apcu_fetch(KEYWORDS_CACHE_KEY_APCU);

$associative = true;
$keywords_cache_array = json_decode($json_encoded_keywords_cache, $associative);

Expand Down Expand Up @@ -102,50 +78,6 @@ public function autocomplete($term)

return $cached_result_array;
} // end of function

/**
// The following code achieves a result similar to the cache-based system
// above, but without case-insensitive matching. The argument for favouring
// a cache-based system over the one below is that the one below makes heavier
// demands on our database and shows poorer performance under load testing.

// Leaving the code below here for the present to facilitate easy comparison
// of caching versus non-caching approaches

// Escaping -- https://www.codeigniter.com/userguide3/database/queries.html#escaping-queries
$escaped_term = $this->db->escape_like_str($term);

// For extra safety, parameterise the query as well

$params = [];
array_push($params, $escaped_term . "%");
array_push($params, $escaped_term);
array_push($params, "%" . $escaped_term . "%");
array_push($params, $escaped_term . "%");

$sql = 'SELECT DISTINCT k.value, "A" AS priority
FROM keywords k
JOIN project_keywords pk
ON k.id = pk.keyword_id
WHERE k.value LIKE ?
UNION
SELECT "=== some other keywords containing \"?\" ===" AS value, "B" AS priority
UNION
SELECT DISTINCT k.value, "C" AS priority
FROM keywords k
JOIN project_keywords pk
ON k.id = pk.keyword_id
WHERE k.value LIKE ?
AND k.value NOT LIKE ?
ORDER BY priority ASC, value ASC
LIMIT 200';

$query = $this->db->query($sql, $params);
return $query->result_array();


}
**/

//return comma delimited list of keywords from project
public function create_keyword_list($project_id)
Expand Down