dotCMS / core

Headless/Hybrid Content Management System for Enterprises
http://dotcms.com
Other
862 stars 468 forks source link

Dashboard: List of Top Assets cannot be retrieved. #10557

Closed joseorsini closed 7 years ago

joseorsini commented 7 years ago

Expected Behavior

If the Dashboard is running for a specific site, once we go to this portlet and select the Site, we should get a list of the total amount of:

Current Behavior

We are getting an exception in logfiles and the "Oops" error message in the browser

screen shot 2017-01-27 at 12 03 26 pm

This is happening on the Dashboard API classes. The getTopAssets() method returns a Cast exception because the amount of Pages it should retrieve is NULL. This is caused by a improper way to retrieve pages (both Legacy and Pages as contents). Once ALL pages are migrated to contents, the Dashboard breaks because the piece of code that counts Legacy Pages doesn't work properly.

Possible Solution

Improve database queries from the method that fails.

Known Workarounds

None.

Steps to Reproduce (for bugs)

  1. In demo site (running 3.6.2), make sure all pages are migrated as contents. On demo, only one page is a Legacy one (/application/ajax/location-clickstream.html, so migrate as content.
  2. Go to Sites portlet and select demo.dotcms.com. Enable Dashboard Run for this site, and then Save/Publish it.
  3. Go to Dashboard portlet and select "demo.dotcms.com" site.
  4. Stacktrace is thrown: https://gist.github.com/joseorsini/4524c8e04620c2690a77d0ff691696d5
  5. Data retrieved by DashboardAPI.getTopAssets()

Query:

SELECT identifier.host_inode AS host_inode, 
(COUNT(contentlet.inode) + (SELECT COUNT(*) 
FROM htmlpage_version_info pageinfo JOIN identifier ON (identifier.id = pageinfo.identifier) 
WHERE identifier.host_inode = '48190c8c-42c4-46af-8d1a-0cd5db894797' 
AND pageinfo.live_inode IS NOT NULL GROUP BY identifier.host_inode)) AS count, 'htmlpage' as asset_type 
FROM contentlet_version_info contentinfo 
JOIN identifier ON (identifier.id = contentinfo.identifier) 
JOIN contentlet ON (contentlet.identifier = identifier.id) 
JOIN structure ON (contentlet.structure_inode=structure.inode)
WHERE identifier.host_inode = '48190c8c-42c4-46af-8d1a-0cd5db894797' AND structure.structuretype = 5 
AND contentinfo.live_inode IS NOT NULL 
GROUP BY identifier.host_inode
UNION ALL
SELECT identifier.host_inode AS host_inode,
count(*) AS count, 'file_asset' AS asset_type 
FROM ((SELECT identifier, live_inode FROM fileasset_version_info) UNION ALL 
      (SELECT identifier, live_inode FROM contentlet_version_info WHERE EXISTS
       (SELECT * FROM contentlet cc JOIN structure st ON (cc.structure_inode = st.inode) 
       WHERE contentlet_version_info.identifier=cc.identifier AND 
       st.structuretype=4 ))) ainfo 

       JOIN identifier ON (identifier.id = ainfo.identifier)
       WHERE identifier.host_inode = '48190c8c-42c4-46af-8d1a-0cd5db894797' AND ainfo.live_inode IS NOT NULL 
       GROUP BY identifier.host_inode 

UNION ALL
SELECT identifier.host_inode as host_inode, 
COUNT(contentlet.inode) AS count, 'contentlet' AS asset_type
FROM contentlet_version_info contentinfo JOIN identifier ON (identifier.id = contentinfo.identifier) 
JOIN contentlet ON (contentlet.identifier = identifier.id) JOIN structure ON (contentlet.structure_inode = structure.inode) 
WHERE identifier.host_inode = '48190c8c-42c4-46af-8d1a-0cd5db894797' AND structure.structuretype<>4 AND
structure.structuretype<>5 AND contentinfo.live_inode IS NOT NULL 
GROUP BY identifier.host_inode;

Results:

              host_inode              | count | asset_type
--------------------------------------+-------+------------
 48190c8c-42c4-46af-8d1a-0cd5db894797 |       | htmlpage
 48190c8c-42c4-46af-8d1a-0cd5db894797 |   562 | file_asset
 48190c8c-42c4-46af-8d1a-0cd5db894797 |   274 | contentlet

Context

Reported by customer: https://my.dotcms.com/tickets/detail.dot?id=8af5d9ad-adc7-43af-a5fa-36a2a143cef9

Your Environment

joseorsini commented 7 years ago

PR: https://github.com/dotCMS/core/pull/10564

bryanboza commented 7 years ago

Fixed, tested on master-4.0 // Oracle // Chrome. I am unable to reproduce.