URLVerify.pm; avoid re-processing same url within the same attempt
authorBill Erickson <berick@esilibrary.com>
Thu, 9 Aug 2012 18:58:41 +0000 (14:58 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 9 Aug 2012 18:58:41 +0000 (14:58 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/URLVerify.pm

index adb4c02..8ea98d5 100644 (file)
@@ -56,7 +56,6 @@ sub validate_session {
     $options ||= {};
 
     # loop through list of URLs / session URLs
-    # TODO: see if we've already tested the url, if so copy the status info  / redirect_to info and move on
     # add a sleep (org setting) to the multisession handler
     # TODO: Avoid testing URLs having the same domain sequentially
 
@@ -402,6 +401,34 @@ sub collect_verify_attempt_and_settings {
     );
 }
 
+
+# finds the url_verfication for any url processed within this 
+# verification attempt whose full_url matches the full_url of 
+# the provided URL.
+sub find_matching_url_for_attempt {
+    my ($e, $attempt, $url) = @_; 
+
+    my $match = $e->json_query({
+        select => {uvuv => ['id']},
+        from => {
+            uvuv => {
+                uvva => {}, # attempt
+                uvu => {} # url
+            }
+        },
+        where => {
+            '+uvu' => {
+                id => {'!=' => $url->id},
+                full_url => $url->full_url
+            }
+        }
+    })->[0];
+
+    return $e->retrieve_url_verify_url_verification($match->{id}) if $match;
+    return undef;
+}
+
+
 =head comment
 
 1. create the verification object and commit.
@@ -428,9 +455,20 @@ sub verify_one_url {
     # begin phase-I DB communication
 
     $e->xact_begin;
+
+    my $match_vcation = find_matching_url_for_attempt($e, $attempt, $url);
+
+    if ($match_vcation) {
+        $logger->info("url: found matching URL in verification attempt [$url_text]");
+        $vcation->redirect_to($match_vcation->url);
+    }
+
     $e->create_url_verify_url_verification($vcation) or return $e->die_event;
     $e->xact_commit;
 
+    # found a matching URL, no need to re-process
+    return {verification => $vcation} if $match_vcation;
+
     # End phase-I DB communication
     # No active DB xact means no cstore timeout concerns.