Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Remove Metadata requirement for IAs to run in DuckPAN #383

Merged
merged 14 commits into from
Apr 26, 2017

Conversation

moollaza
Copy link
Member

@moollaza moollaza commented Nov 21, 2016

Background

Devs shouldn't need an IA page in dev status to play with DuckPAN.

With the switch to the Programming Mission, devs are currently force to open PRs to test any new IAs, which means they are required to open PRs for non-mission IAs as well, which bloats the repo with PRs.

We should enable DuckPAN to use temporary metadata in order to trigger local IA's and show results.

This will help keep the repos clean with only PRs for IAs that are real and intended to move forward.

Changes

  • Update DDG.pm to gracefully handle IAs without metadata and use a temporary ID based on the Perl module
  • Update Web.pm to generate "fake" metadata when none exists to be passed along to frontend JS to create IA tab and display result
    • Also, notify user when no metadata was found, and that temporary metadata is being used instead. Provide better explanation of how to get real metadata and IA Page working
  • Minor fix to Server.pm that fixes warning

/cc @mintsoft

@moollaza
Copy link
Member Author

@zachthompson @mintsoft I've pushed some commits. This now prevents the message and DuckPAN Query works fine.

However, for DuckPAN Server, we have a few more direct calls to DDG::Meta::Data to grab the JS for Spices and the id for Goodies.

Any ideas on how we can bypass these?

These are the lines that we need to adjust:

@zachthompson
Copy link
Contributor

@moollaza Think we'd need to add module-to-id mapping back to duckpan. When the first lookup fails, derive the id from the module, push it, and it should work for the get_js() call.

@mintsoft
Copy link
Collaborator

mintsoft commented Nov 26, 2016

@moollaza someone new on slack ran into this today: https://duckduckhack.slack.com/archives/ask-anything/p1480142217001441

@moollaza
Copy link
Member Author

@zachthompson this is now ready for further review.

/cc @mintsoft @GuiltyDolphin

I have tested this by creating a new Goodie and Spice without metadata and running duckpan server, and duckpan query. In both cases the correct results were displayed.

Here's a screenshot of a "request headers" Spice that has no Metadata, showing a result:

2__zeroclickinfo-spice__duckpan_-e_-i____p5-app-duckpan_lib_server__perl__and_request_headers_at_duckduckgo

moollaza and others added 2 commits December 28, 2016 17:12
…ahir/remove-metadata-requirement

* 'master' of github.com:duckduckgo/p5-app-duckpan:
  Fix handling of nonexistant test
  Ensure Metadata lookup was successful, exit if not
  Fix 'no warnings' declaration
  Check if we're dealing with Fathead regardless of perl_module existance
  ensure perl_module is defined before using
  Create HTTP::Headers obj from headers hash
  Only grab metadata once
  Add Fathead support to DuckPAN Test
sub change_css {
my ( $self, $css ) = @_;
my $hostname = $self->hostname;
$css =~ s!:\s*url\((["'])?/!:url\($1http://$hostname/!g;

$css =~ s|:\s*url\(["']([^'"]+)["']\)|:url\("http://$hostname/$1")|gi;
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes a separate bug I ran into...

Copy link
Contributor

Choose a reason for hiding this comment

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

Which is what?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem was related to our parsing and re-writing of relative urls in the CSS files we pull down from duckduckgo.com.

After looking into this more, I've realized that re-writing the CSS isn't even necessary because Web.pm proxies relative urls to the appropriate upstream host.

Removing the body of this function has no effect on the SERP AFAICT.

I will remove these changes

@@ -74,11 +92,21 @@ sub get_blocks_from_current_dir {
if (my $ia = $self->app->get_ia_by_name($arg)) {
$class = $ia->{perl_module};
}
elsif ($arg =~ /_/) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about IDs with no underscore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch 👍

I will check if it matches /^[a-z0-9_]+$/ which resembles a lowercased ID.

If there are uppercase letters we can assume it's a Perl Module Name.

@moollaza
Copy link
Member Author

@zachthompson I've revised the logic here I think I've now accounted for any kind of valid input and it now bails on invalid inputs:

1____projects_zeroclickinfo-goodies__zsh_

@moollaza
Copy link
Member Author

Here's an example of all the cases:

1____projects_zeroclickinfo-goodies__zsh_

@zachthompson
Copy link
Contributor

Thanks.

@zachthompson zachthompson merged commit 390d577 into master Apr 26, 2017
@zachthompson zachthompson deleted the zaahir/remove-metadata-requirement branch April 26, 2017 15:44
@mintsoft mintsoft mentioned this pull request Jul 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants