Ignore:
Timestamp:
Feb 13, 2015, 5:10:11 PM (9 years ago)
Author:
casties
Branch:
default
Message:

make admin ui view of all annotations scale better.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java

    r98 r101  
    6262public class AnnotationStore {
    6363
    64     protected static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.neo4j.AnnotationStore");
     64    protected static Logger logger = Logger.getLogger(AnnotationStore.class.getCanonicalName());
    6565
    6666    protected GraphDatabaseService graphDb;
     
    257257
    258258    /**
     259     * Returns the total number of Annotations.
     260     *
     261     * @return number of annotations
     262     */
     263    public int getAnnotationCount() {
     264        int num = -1;
     265        Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION);
     266        try (Transaction tx = graphDb.beginTx()) {
     267            IndexHits<Node> annotNodes = idx.query("id", "*");
     268            num = annotNodes.size();
     269            tx.success();
     270        }
     271        return num;
     272    }
     273   
     274    /**
    259275     * Returns List of Annotations. Key has to be indexed.
    260276     *
    261277     * @param key
    262278     * @param query
    263      * @return
    264      */
    265     public List<Annotation> getAnnotations(String key, String query) {
     279     * @param limit
     280     * @param offset
     281     * @return
     282     */
     283    public List<Annotation> getAnnotations(String key, String query, int limit, int offset) {
     284        long ts = System.currentTimeMillis();
    266285        ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    267286        Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION);
     
    272291        try (Transaction tx = graphDb.beginTx()) {
    273292            IndexHits<Node> annotNodes = idx.query(key, query);
     293            int cnt = 0;
     294            int max = offset + limit;
    274295            for (Node annotNode : annotNodes) {
     296                cnt += 1;
     297                if (cnt < offset) continue;
    275298                Annotation annotation = createAnnotationFromNode(annotNode);
    276299                annotations.add(annotation);
    277             }
    278             tx.success();
    279         }
     300                if (limit > 0 && cnt >= max) {
     301                    annotNodes.close();
     302                    break;
     303                }
     304            }
     305            tx.success();
     306        }
     307        logger.finer("got "+annotations.size()+" annotations in "+(System.currentTimeMillis()-ts)+"ms");
    280308        return annotations;
    281309    }
Note: See TracChangeset for help on using the changeset viewer.