Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #129 from MITLibraries/124_newitem_count
Browse files Browse the repository at this point in the history
Improves calculation for new subscription delivery count
  • Loading branch information
Richard Rodgers committed Mar 31, 2015
2 parents 0ace9e2 + 30e9bd5 commit f6e865e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/models/Subscriber.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ case class Subscriber(id: Int, // DB key
Subscription.make(id, topic.id, interestIn(topic.scheme_id).get.action, created, new Date)
}

def newItemCountFor(topicId: Int) = {
DB.withConnection { implicit c =>
val count = SQL(
"""
select count(*) as c from item_topic
where topic_id = {topic_id}
and item_created > {created}
and not exists (
select 1 from transfer
where subscriber_id = {sub_id}
and item_id = item_topic.item_id
)
"""
).on('topic_id -> topicId, 'created -> created, 'sub_id -> id).apply.head
count[Long]("c")
}
}

def interestsWithAction(action: String): List[Interest] = {
DB.withConnection { implicit c =>
SQL("select * from interest where action = {action} and subscriber_id = {id}")
Expand Down
2 changes: 1 addition & 1 deletion app/views/topic/show.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3><a href="@routes.Application.scheme(topic.scheme.get.id)">@topic.scheme.get.
<span><a rel="tooltip" title="Cancel subscription to this topic" href="@routes.Application.topicSubscribe(topic.id, true)" class="btn btn-primary btn-large">Unsubscribe &raquo;</a></span>
} else {
@if(sub.get.hasInterest(topic.scheme_id)) {
<span><a rel="tooltip" title="Subscribe to this topic" href="@routes.Application.topicSubscribe(topic.id)" class="btn btn-primary btn-large">Subscribe <span class="badge">@topic.itemCountSince(sub.get.created)</span> &raquo;</a></span>
<span><a rel="tooltip" title="Subscribe to this topic" href="@routes.Application.topicSubscribe(topic.id)" class="btn btn-primary btn-large">Subscribe <span class="badge">@sub.get.newItemCountFor(topic.id)</span> &raquo;</a></span>
}
}
}
Expand Down

0 comments on commit f6e865e

Please sign in to comment.