audio_recordings.pm: active audio uploads

If audio files become inactive because a new file is uploaded, the new
file is marked as active and the old file is marked as not active.
This allows fastly querying events and their active upload file.
Before this change all event's audio files were found and needed to be
filtered afterwards to get a set of unique events.
This commit is contained in:
Milan
2020-12-19 22:01:26 +01:00
parent 78f9f3c538
commit e3c3991db6
4 changed files with 81 additions and 34 deletions

View File

@@ -270,3 +270,10 @@ ADD COLUMN `update_event_field_content_format` TINYINT(1) UNSIGNED NOT NULL AFTE
ALTER TABLE `calcms_events` ALTER TABLE `calcms_events`
ADD COLUMN `listen_key` VARCHAR(100) NULL; ADD COLUMN `listen_key` VARCHAR(100) NULL;
ALTER TABLE `calcms_audio_recordings`
ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 0 AFTER `event_id`;
ALTER TABLE `calcms`.`calcms_audio_recordings`
ADD INDEX `active_index` (`active`);

View File

@@ -77,6 +77,7 @@ sub get($$) {
,project_id ,project_id
,studio_id ,studio_id
,event_id ,event_id
,active
,path ,path
,size ,size
,created_by ,created_by
@@ -128,7 +129,9 @@ sub update($$$) {
$query .= ' and id=?'; $query .= ' and id=?';
push @$bind_values, $entry->{id}; push @$bind_values, $entry->{id};
} }
return db::put( $dbh, $query, $bind_values ); my $result = db::put( $dbh, $query, $bind_values );
update_active($config, $dbh, $entry);
return $result;
} }
# insert playout entry # insert playout entry
@@ -142,25 +145,24 @@ sub insert ($$$) {
return undef unless defined $entry->{event_id}; return undef unless defined $entry->{event_id};
return undef unless defined $entry->{path}; return undef unless defined $entry->{path};
return db::insert( $entry = {
$dbh, project_id => $entry->{project_id},
'calcms_audio_recordings', studio_id => $entry->{studio_id},
{ event_id => $entry->{event_id},
project_id => $entry->{project_id}, path => $entry->{path},
studio_id => $entry->{studio_id}, size => $entry->{size},
event_id => $entry->{event_id}, created_by => $entry->{created_by},
path => $entry->{path}, eventDuration => $entry->{eventDuration},
size => $entry->{size}, audioDuration => $entry->{audioDuration},
created_by => $entry->{created_by}, rmsLeft => $entry->{rmsLeft},
eventDuration => $entry->{eventDuration}, rmsRight => $entry->{rmsRight},
audioDuration => $entry->{audioDuration}, processed => $entry->{processed},
rmsLeft => $entry->{rmsLeft}, mastered => $entry->{mastered} || '0',
rmsRight => $entry->{rmsRight}, };
processed => $entry->{processed},
mastered => $entry->{mastered} || '0',
}
);
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
update_active($config, $dbh, $entry);
return $result;
} }
# delete playout entry # delete playout entry
@@ -175,12 +177,48 @@ sub delete ($$$) {
return undef unless defined $entry->{path}; return undef unless defined $entry->{path};
my $query = qq{ my $query = qq{
delete delete
from calcms_audio_recordings from calcms_audio_recordings
where project_id=? and studio_id=? and event_id=? and path=? where project_id=? and studio_id=? and event_id=? and path=?
}; };
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ]; my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
return db::put( $dbh, $query, $bind_values ); my $result = db::put( $dbh, $query, $bind_values );
update_active($config, $dbh, $entry);
return $result;
}
sub update_active($$$) {
my $config = shift;
my $dbh = shift;
my $entry = shift;
return undef unless defined $entry->{project_id};
return undef unless defined $entry->{studio_id};
return undef unless defined $entry->{event_id};
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id} ];
my $query = qq{
update calcms_audio_recordings
set active=0
where project_id=? and studio_id=? and event_id=? and active=1
};
db::put( $dbh, $query, $bind_values );
$query = qq{
select max(id) id from calcms_audio_recordings
where project_id=? and studio_id=? and event_id=?
};
my $entries = db::get( $dbh, $query, $bind_values );
my $max = $entries->[0];
return undef unless defined $max->{id};
$query = qq{
update calcms_audio_recordings
set active=1
where id=?
};
return db::put( $dbh, $query, [$max->{id}] );
} }
sub error($) { sub error($) {

View File

@@ -1148,7 +1148,7 @@ sub get_query($$$) {
# add recordings table # add recordings table
if ( $params->{recordings} eq '1' ) { if ( $params->{recordings} eq '1' ) {
$query .= "\n left join calcms_audio_recordings ar on e.id=ar.event_id"; $query .= "\n left join calcms_audio_recordings ar on e.id=ar.event_id and ar.active=1";
} }
if ( scalar @$where_cond > 0 ) { if ( scalar @$where_cond > 0 ) {

View File

@@ -495,7 +495,7 @@ sub get_events ($$) {
my $conditions = ''; my $conditions = '';
if ( @conditions > 0 ) { if ( @conditions > 0 ) {
$conditions = ' and ' . join( ' and ', @conditions ); $conditions = ' where ' . join( ' and ', @conditions );
} }
my $limit = ''; my $limit = '';
@@ -504,17 +504,19 @@ sub get_events ($$) {
} }
my $query = qq{ my $query = qq{
select * select se.*,e.*
,date(start) start_date ,date(start) start_date
,date(end) end_date ,date(end) end_date
,weekday(start) weekday ,weekday(start) weekday
,weekofyear(start) week_of_year ,weekofyear(start) week_of_year
,dayofyear(start) day_of_year ,dayofyear(start) day_of_year
,start_date day ,start_date day
,id event_id ,e.id event_id
from calcms_series_events se, calcms_events e ,ar.path path
where se.event_id = e.id from calcms_series_events se
$conditions inner join calcms_events e on se.event_id = e.id
left join calcms_audio_recordings ar on se.event_id=ar.event_id and ar.active=1
$conditions
order by start_date desc order by start_date desc
$limit $limit
}; };