summaryrefslogtreecommitdiffstats
path: root/Bugzilla/User.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2016-11-20 00:12:39 +0100
committerDylan William Hardison <dylan@hardison.net>2017-01-04 23:30:47 +0100
commit419f3ae9fd57fc4e03146a830f7ed780ace83937 (patch)
treef368b61dab21eb036e4b91e1ec947a4b9eeabae9 /Bugzilla/User.pm
parent840bbad83e4672fc84083437e384f0d332020f53 (diff)
downloadbugzilla-419f3ae9fd57fc4e03146a830f7ed780ace83937.tar.gz
bugzilla-419f3ae9fd57fc4e03146a830f7ed780ace83937.tar.xz
Bug 1307478 - Elasticsearch Indexer / Bulk Indexer
Diffstat (limited to 'Bugzilla/User.pm')
-rw-r--r--Bugzilla/User.pm76
1 files changed, 76 insertions, 0 deletions
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 0eb9587eb..69885f57c 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -30,6 +30,7 @@ use Scalar::Util qw(blessed);
use Storable qw(dclone);
use URI;
use URI::QueryParam;
+use Role::Tiny::With;
use base qw(Bugzilla::Object Exporter);
@Bugzilla::User::EXPORT = qw(is_available_username
@@ -123,6 +124,81 @@ use constant VALIDATOR_DEPENDENCIES => {
use constant EXTRA_REQUIRED_FIELDS => qw(is_enabled);
+with 'Bugzilla::Elastic::Role::Object';
+
+sub ES_TYPE { 'user' }
+
+sub ES_OBJECTS_AT_ONCE { 2000 }
+
+sub ES_SELECT_UPDATED_SQL {
+ my ($class, $mtime) = @_;
+
+ my $sql = q{
+ SELECT DISTINCT
+ object_id
+ FROM
+ audit_log
+ WHERE
+ class = 'Bugzilla::User' AND at_time > FROM_UNIXTIME(?)
+ };
+ return ($sql, [$mtime]);
+}
+
+sub ES_SELECT_ALL_SQL {
+ my ($class, $last_id) = @_;
+
+ my $id = $class->ID_FIELD;
+ my $table = $class->DB_TABLE;
+
+ return ("SELECT $id FROM $table WHERE $id > ? AND is_enabled ORDER BY $id", [$last_id // 0]);
+}
+
+sub ES_PROPERTIES {
+ return {
+ suggest_user => {
+ type => 'completion',
+ analyzer => 'folding',
+ search_analyzer => 'folding',
+ payloads => \1,
+ },
+ suggest_nick => {
+ type => 'completion',
+ analyzer => 'simple',
+ search_analyzer => 'simple',
+ payloads => \1,
+ },
+ login => { type => 'string' },
+ name => { type => 'string' },
+ is_enabled => { type => 'boolean' },
+ };
+}
+
+sub es_document {
+ my ( $self, $timestamp ) = @_;
+ my $weight = eval { $self->last_activity_ts ? datetime_from($self->last_activity_ts)->epoch : 0 } // 0;
+ my $doc = {
+ login => $self->login,
+ name => $self->name,
+ is_enabled => $self->is_enabled,
+ suggest_user => {
+ input => [ $self->login, $self->name ],
+ output => $self->identity,
+ payload => { name => $self->login, real_name => $self->name },
+ weight => $weight,
+ },
+ };
+ if ($self->name && $self->name =~ /:(\w+)/) {
+ my $ircnick = $1;
+ $doc->{suggest_nick} = {
+ input => [ $ircnick ],
+ output => $self->login,
+ payload => { name => $self->login, real_name => $self->name, ircnick => $ircnick },
+ weight => $weight,
+ };
+ }
+
+ return $doc;
+}
################################################################################
# Functions
################################################################################