Skip to content
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

Reveal keywords on project's catalogue page #225

Merged
merged 7 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
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'] = 2;
$config['migration_version'] = 4;
$config['migration_path'] = APPPATH . 'migrations/';
32 changes: 32 additions & 0 deletions application/controllers/cron/Keywords_stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Keywords_stats extends CI_Controller
{
public function update_keywords_stats()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to remember to add a line to https://github.com/LibriVox/librivox-ansible/blob/master/roles/common/files/daily-cron to actually run this. Is daily enough?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From admin side, I'd say so. We're used to some processes running overnight, so for anything that isn't immediate, that's a "no surprise" interval. 👍

{
// Some keywords are not in use at all.
// Initialise count field to zero before tallying counts.

$sql = '
UPDATE keywords
SET count = 0';
$this->db->query($sql);

$sql = '
UPDATE keywords
JOIN
(SELECT pk.keyword_id as keyword_id, COUNT(pk.project_id) AS count
FROM project_keywords pk
GROUP BY 1
) as sub
ON keywords.id = sub.keyword_id
SET keywords.count = sub.count ';
$this->db->query($sql);

}
}


/* End of file Keyword_stats.php */
/* Location: ./application/controllers/cron/Keyword_stats.php */

22 changes: 22 additions & 0 deletions application/migrations/003_add_keywords_count_field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Add_keywords_count_field extends CI_Migration {

public function up()
{
$fields = array(
'count' => array('type' => 'INT',
'default' => '0',
'after' => 'value')
);
$this->dbforge->add_column('keywords', $fields);
}

public function down()
{
$this->dbforge->drop_column('keywords', 'count');
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Drop_redundant_keywords_from_projects extends CI_Migration {

public function up()
{
$sql = '
DELETE pk2.*
FROM project_keywords pk2
WHERE keyword_id IN
(
SELECT id
FROM keywords k
WHERE k.value in (
"librivox",
"ibrivox",
"llibrivox",
"librixox",
"librivox;",
"libriox",
"libirivox",
"librivos",
"audio",
"audiobook",
"audiobooks",
"audio books",
"audio book",
"audioboek",
"audiobuch",
"audiobooklibrivox",
"audibook",
"audioook",
"autiobook",
"audiobook:",
"audioboo",
"audiolibro",
"audio libro",
"audiolibros",
"audiolivre",
"audiolivro"
)
)';
$this->db->query($sql);
}

public function down()
{
;
}
}
1 change: 0 additions & 1 deletion application/models/Project_keyword_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class Project_keyword_model extends MY_Model {



}

/* End of file project_keyword.php */
Expand Down