Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

In attach_story_data_to_stories(), don't overwrite existing fields #730

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pypt
Copy link
Contributor

@pypt pypt commented Sep 29, 2020

Hey Hal!

I know you're superbusy with other stuff, but could you have a quick look?

In #729 (and possibly #725), it looks like MediaWords::DBI::Stories::attach_story_data_to_stories() used to reset $list_field key to an empty arrayref on every call, thus making this subroutine not work when it was called multiple times, e.g. when data was being "attached" in chunks:

my $iter = natatime(100, @{ $stories } );
while ( my @chunk_stories = $iter->() )
{
my $chunk_ids_list = join( ',', map { int( $_->{ stories_id } ) } @chunk_stories );
my $tag_data = $db->query(
<<SQL
SELECT
s.stories_id::int,
t.tags_id,
t.tag,
ts.tag_sets_id,
ts.name AS tag_set
FROM stories_tags_map AS s
JOIN tags AS t
ON t.tags_id = s.tags_id
JOIN tag_sets AS ts
ON ts.tag_sets_id = t.tag_sets_id
WHERE stories_id in ( $chunk_ids_list )
ORDER BY t.tags_id
SQL
)->hashes;
$stories = MediaWords::DBI::Stories::attach_story_data_to_stories( $stories, $tag_data, 'story_tags' );
}

I've now made the subroutine merge the input $story_data with whatever might already be in the parameter $stories under $list_field (if anything). There's also a test that verifies that the subroutine behaves as intended.

Does it look good to you?

@pypt pypt added the bug label Sep 29, 2020
@pypt pypt requested a review from hroberts September 29, 2020 19:24
@pypt pypt self-assigned this Sep 29, 2020
@hroberts
Copy link
Contributor

looks good to me. nice catch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants