Changeset 4829


Ignore:
Timestamp:
Mar 23, 2009, 3:28:03 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #903: Experiment Explorer is slow

Store list of position in the static file cache. Removed index on 'position' column.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/ExperimentExplorer.java

    r4815 r4829  
    3636import javax.servlet.jsp.PageContext;
    3737
     38import net.sf.basedb.util.StaticCache;
    3839import net.sf.basedb.util.Values;
    3940import net.sf.basedb.clients.web.formatter.FormatterFactory;
    4041import net.sf.basedb.clients.web.taglib.table.TableColumn;
    4142import net.sf.basedb.core.AnnotationType;
     43import net.sf.basedb.core.Application;
    4244import net.sf.basedb.core.BaseException;
    4345import net.sf.basedb.core.BioAssay;
     
    848850  }
    849851 
     852  @SuppressWarnings("unchecked")
    850853  private void initReporterCache(DbControl dc)
    851854  {
     
    854857    if (posCache == null)
    855858    {
    856       Select spotPos = Dynamic.select(VirtualTable.SPOT, VirtualColumn.POSITION);
    857       DynamicSpotQuery posQuery = bas.getSpotData();
    858       posQuery.select(spotPos);
    859       posQuery.order(Orders.asc(Expressions.selected(spotPos)));
    860       posQuery.setDistinct(true);
    861       DynamicResultIterator it = posQuery.iterate(dc);
    862       List<Integer> posList = new ArrayList<Integer>(bas.getNumReporters());
    863       try
    864       {
    865         while (it.hasNext())
     859      StaticCache staticCache = Application.getStaticCache();
     860      String cacheKey = "explorer/bioassayset." + bas.getId() + "/poslist.ser";
     861      List<Integer> posList = (List<Integer>)staticCache.load(cacheKey, 100);
     862      if (posList == null)
     863      {
     864        Select spotPos = Dynamic.select(VirtualTable.SPOT, VirtualColumn.POSITION);
     865        DynamicSpotQuery posQuery = bas.getSpotData();
     866        posQuery.select(spotPos);
     867        posQuery.order(Orders.asc(Expressions.selected(spotPos)));
     868        posQuery.setDistinct(true);
     869        DynamicResultIterator it = posQuery.iterate(dc);
     870        posList = new ArrayList<Integer>(bas.getNumReporters());
     871        try
    866872        {
    867           posList.add(it.next().getInt(1));
     873          while (it.hasNext())
     874          {
     875            posList.add(it.next().getInt(1));
     876          }
     877          staticCache.store(cacheKey, posList, 100);
    868878        }
    869       }
    870       catch (SQLException ex)
    871       {
    872         throw new BaseException(ex);
    873       }
    874       finally
    875       {
    876         it.close();
     879        catch (SQLException ex)
     880        {
     881          throw new BaseException(ex);
     882        }
     883        finally
     884        {
     885          it.close();
     886        }
    877887      }
    878888      posCache = new int[posList.size()];
  • trunk/src/core/net/sf/basedb/core/VirtualColumn.java

    r4817 r4829  
    9292      !INDEXED, !NULLABLE, PRIMARY_KEY);
    9393
    94   /**
    95     This column stores the (indexed) data cube position coordinate.
    96   */
    97   public static final VirtualColumn INDEXED_POSITION =
    98     new VirtualColumn("position", "position", Hibernate.INTEGER, 0,
    99       INDEXED, !NULLABLE, PRIMARY_KEY);
    100  
    10194  /**
    10295    This column stores the data cube filter number.
  • trunk/src/core/net/sf/basedb/core/VirtualTable.java

    r4817 r4829  
    5757    VirtualColumn.LAYER,
    5858    VirtualColumn.COLUMN,
    59     VirtualColumn.INDEXED_POSITION
     59    VirtualColumn.POSITION
    6060  )
    6161  {
  • trunk/src/core/net/sf/basedb/util/StaticCache.java

    r4827 r4829  
    5353  with the any of the {@link #read(String, int)} or {@link #write(String, InputStream, int)}
    5454  methods and their variants. It can also be used to store any {@link Serializable}
    55   object with {@link #store(String, Serializable, int)} and {@link #load(String, int)}.
     55  object with {@link #store(String, Object, int)} and {@link #load(String, int)}.
    5656  <p>
    5757 
     
    305305   
    306306    @param key The cache key
    307     @param object The object to store in the cache
     307    @param object The object to store in the cache, it must be a
     308      {@link Serializable} object
    308309    @param timeout A timeout in milliseconds to wait for a write lock
    309310      on the requested cache entry
    310311    @return TRUE if the object could be stored, FALSE otherwise
    311312  */
    312   public boolean store(String key, Serializable object, int timeout)
    313     throws IOException
     313  public boolean store(String key, Object object, int timeout)
    314314  {
    315315    if (disabled) return false;
    316316    OutputStream out = null;
     317    boolean stored = false;
    317318    try
    318319    {
     
    323324        oos.writeObject(object);
    324325        oos.flush();
    325       }
     326        stored = true;
     327      }
     328    }
     329    catch (IOException ex)
     330    {
     331      log.warn("Could not store cached entry: " + key, ex);
    326332    }
    327333    finally
    328334    {
    329       if (out != null) out.close();
    330     }
    331     return true;
     335      if (out != null)
     336      {
     337        try
     338        {
     339          out.close();
     340        }
     341        catch (IOException ex)
     342        {}
     343      }
     344    }
     345    return stored;
    332346  }
    333347 
     
    341355      exists or if a read lock couldn't be aquired
    342356  */
    343   public Serializable load(String key, int timeout)
    344     throws IOException
     357  public Object load(String key, int timeout)
    345358  {
    346359    if (disabled) return null;
     
    363376      }
    364377    }
     378    catch (IOException ex)
     379    {
     380      log.warn("Could not load cached entry: " + key, ex);
     381    }
    365382    finally
    366383    {
    367       if (in != null) in.close();
     384      if (in != null)
     385      {
     386        try
     387        {
     388          in.close();
     389        }
     390        catch (IOException ex)
     391        {}
     392      }
    368393    }
    369394    return object;   
Note: See TracChangeset for help on using the changeset viewer.