Issue 19646

Topics: Troubleshooting
Developer
Apr 25, 2013 at 4:43 PM
Edited Apr 25, 2013 at 6:34 PM
https://orchard.codeplex.com/workitem/19646

continuing the discussion with sebastien on what I found here...

Hey Sebastein,

While resolving issue 19645, I noticed that 'process' was always set to true in MediaShapes.MediaUrl().
This would cause image processing and recaching of the image to occur every time.
I finished fixing issue 19645 first, where i changed the key used for caching, and I noticed that the issue still occurs.

Setup:
With a brand new Orchard site, cooked with the default recipe, and the following recipe run.
Upload an image to your Media Library, and use it in the newly created "Page Image" field of the home page.
<?xml version="1.0"?>
<Orchard>
  <Recipe>
    <Name>Issue 19646</Name>
    <Description></Description>
    <Author></Author>
    <WebSite></WebSite>
    <Tags></Tags>
    <Version>1.0</Version>
  </Recipe>
  
  <Feature enable="Orchard.MediaLibrary" />
  
  <Metadata>
    <Types>
      <Page>
        <Page />
      </Page>
    </Types>
    <Parts>
      <Page>
        <PageImage.MediaLibraryPickerField DisplayName="Page Image" MediaLibraryPickerFieldSettings.Required="False" MediaLibraryPickerFieldSettings.Multiple="False" />
      </Page>
    </Parts>
  </Metadata>
</Orchard>
Breakdown:
https://orchard.codeplex.com/SourceControl/network/forks/StanleyGoldman/Issue19646attempt2?branch=1.x

In changeset 421dfaeb79a9, I added some logging to help me prove the issue.
2013-04-25 09:40:22,580 [5] Orchard.MediaProcessing.Shapes.MediaShapes - Processed file no longer exists, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:22,592 [5] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:33,013 [16] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:33,015 [16] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:34,497 [6] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:34,499 [6] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:40:37,836 [15] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
I suspected that the not operator on line 87 to be the culprit, but I wanted to be sure I didn't create the issue while resolving 19645.

I branched from before I made the 19645 fix and grafted the logging changeset onto that.
Branch: issue19646.pre19645
2013-04-25 09:50:36,935 [5] Orchard.MediaProcessing.Shapes.MediaShapes - Processed file no longer exists, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:50:36,948 [5] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:50:50,534 [11] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:50:50,536 [11] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:50:58,912 [11] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:50:58,914 [11] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:51:11,977 [16] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is not null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:51:11,980 [16] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
I observed that the issue predated my 19645 fix and I removed the not operator that bothered me 55b81bbf4046
2013-04-25 09:56:09,339 [5] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:56:09,352 [5] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 09:56:18,734 [16] Orchard.MediaProcessing.Shapes.MediaShapes - An error occured while rendering shape Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
System.ArgumentException: File ~/Media/Default/Images/Jellyfish.jpg does not exist
   at Orchard.FileSystems.Media.FileSystemStorageProvider.GetFile(String path) in d:\OceanEddy\Orchard-19646-attempt2\src\Orchard\FileSystems\Media\FileSystemStorageProvider.cs:line 117
   at Orchard.MediaProcessing.Shapes.MediaShapes.MediaUrl(Object Shape, Object Display, TextWriter Output, String Profile, String Path, ContentItem ContentItem, FilterRecord CustomFilter)
Added some additional try/catches 11112a78378d
2013-04-25 10:19:35,392 [4] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 10:19:35,406 [4] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 10:19:41,931 [13] Orchard.MediaProcessing.Shapes.MediaShapes - An error occured while rendering shape Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
System.Exception: Error Retrieving pathLastUpdated ---> System.ArgumentException: File ~/Media/Default/Images/Jellyfish.jpg does not exist
   at Orchard.FileSystems.Media.FileSystemStorageProvider.GetFile(String path) in d:\OceanEddy\Orchard-19646-attempt2\src\Orchard\FileSystems\Media\FileSystemStorageProvider.cs:line 117
   at Orchard.MediaProcessing.Shapes.MediaShapes.MediaUrl(Object Shape, Object Display, TextWriter Output, String Profile, String Path, ContentItem ContentItem, FilterRecord CustomFilter)
   --- End of inner exception stack trace ---
   at Orchard.MediaProcessing.Shapes.MediaShapes.MediaUrl(Object Shape, Object Display, TextWriter Output, String Profile, String Path, ContentItem ContentItem, FilterRecord CustomFilter)
At that point I understood the problem to be with obtaining the last modified date of the original file.

I refactored some logic out of GetImage to help me determine what kind of image it was 14b807150dd2

Then applied that knowledge to help me get the last updated time 767bf7b7e2db

After those changes, the image processing only occurs when it should. I took a moment to test that, and made sure that the cache repopulated after modifying the file on disk.
2013-04-25 10:50:03,178 [4] Orchard.MediaProcessing.Shapes.MediaShapes - FilePath is null, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 10:50:03,191 [4] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 10:52:07,988 [13] Orchard.MediaProcessing.Shapes.MediaShapes - Original file more recent, processing required, profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
2013-04-25 10:52:07,990 [13] Orchard.MediaProcessing.Shapes.MediaShapes - Processing profile Transform_Resize_w_200_h_200_m_crop_a_middlecenter_c_ for image ~/Media/Default/Images/Jellyfish.jpg
Q.E.D.

My first pull request wasn't as clean, so you were right to question me.
Having had to redo it, it's a lot cleaner now.

Let me know if you have any questions.
-Stan